|
IKVM11
11
Java SE 11 Virtual Machine for .NET
|
IKVM11 can be added to a .NET SDK-style project by installing the IKVM11 NuGet package provided on nuget.org. This can be done by either running dotnet add package IKVM11 or by manually editing your project file and inserting a PackageReference.
Upon referencing the IKVM11 package the Java SE 11 base class library should be immediately available to .NET code.
Java classes are made available as .NET classes mapping the Java package name to the .NET namespace name. Java primitive types are exposed to .NET primitive types.
The IkvmReference functionality is an extension to the MSBuild system for SDK-style .NET projects that allows easy referencing of Java resources such as classes and JARs from .NET projects. The simplest case is just adding a JAR file to your .NET project:
When used IkvmReference will attempt to convert this JAR file into a .NET assembly and provide IntelliSense and build support. After IKVM11 has had a chance to convert the JAR file you should be able to simply access classes from the file using standard C# code. Java packages appear as normal namespaces.
IkvmReference inherits the same capabilities as the Reference element. In fact the IkvmReference simply produces Reference entries in the background after converting the Java code to .NET code. In addition to this IkvmReference provides a number of metadata options to customize that conversion process.
IncludeInclude can be one of:
Compile is used instead)AssemblyName, AssemblyVersion and AssemblyFileVersionIKVM11 attempts to infer the assembly name from the original Java code with the following steps:
Automatic-Module-Name specification. This is a specification that originated with JDK9.Specifies the filename containing the cryptographic key. When this option is used, the compiler inserts the public key from the specified file into the assembly manifest and then signs the final assembly with the private key.
This option causes the compiler to reserve space in the output file so that a digital signature can be added later. Use DelaySign if you only want to place the public key in the assembly. The DelaySign option has no effect unless used with KeyFile.
A semi-colon separated list of Java class path items to compile into the assembly. By default this value is the Identity of the item, if the identity of the item is an existing JAR file or directory (not yet supported). MSBuild globs are supported to reference multiple JAR or .class files.
Optional semi-colon separated list of other IkvmReference identity values to specify as a reference to the current one. For example, if foo.jar depends on bar.jar, include both as IkvmReference items, but specify the identity of bar.jar on the References metadata of foo.jar. This is required if you intend to include two different JAR files to produce two different assemblies and the code of these items depends upon each other.
In the above case we want to compile two different Java items into two different output assemblies. However, classes within bar.jar depend on classes within foo.jar. When References is present the build process can use this information to find classes from one in the other. The ultimate result is two output assemblies that that reference each other. One has to be built before the other, and so this information is required.
For more information see Compilation.
A fully qualified classs name of the custom ClassLoader implementation to use as a delegation parent. Examples include ikvm.runtime.AppDomainAssemblyClassLoader and ikvm.runtime.ClassPathAssemblyClassLoader.
For more information see ClassLoaders.