Roughly 2 months ago, a new long-awaited version of IKVM was announced.
The killer feature of the 8.2 release is the support of .NET Core. So, now, IKVM can translate JAR files to .NET Core compatible DLLs. Woohoo!
Last week I migrated to the new IKVM two projects and can share my first impressions:
First of all, it works! I am glad to see that project was revived and .NET Core was supported. It really opens up a lot of new possibilities for .NET developers. But, not everything is perfect yet:
- No support for JDK higher than JDK 8.
This means that you cannot use JAR files compiled by JDK 9 for example. It is quite an old limitation, and the project requires an incredible amount of work to catch up with later versions. Everyone can help here 😉
- IKVM Compiler (IKMVc) is hard to use.
Currently project ships two compilers (IKVMc): one for .NET Framework and one for .NET Core as well as two sets of runtime libraries for two runtimes. You should use .NET Core version of IKVMc with .NET Core set of runtime libraries to produce .NET Core version of a JAR file.
Is it confusing and quite hard to use! In most cases, you should not IKVMc use directly anymore, because the project gives you access to MavenReference / MSBuild integration (read further for details).
- You should build on Windows with .NET Core 3.1 installed.
Windows is the only fully supported platform (once again, it only build-time dependency, produced DLLs will work on all platforms including Linux & macOS, and runtimes like .NET 6).
Linux version almost works, except for Sockets support.
The macOS version does not exist yet but looks like something is coming…
MavenReference is a very cute new addition to the IKVM family of tools that hide from you the complexity of IKVMc. All you need is to edit your csprof/fsproj file and reference to Maven package! (You may think about Maven like a Nuget from Java world)
<ItemGroup> <PackageReference Include="IKVM" Version="8.2.1" /> <PackageReference Include="IKVM.Maven.Sdk" Version="1.0.1" /> <MavenReference Include="org.apache.opennlp:opennlp-tools" Version="1.9.4" /> </ItemGroup>
- IKVM package contains Java runtime libraries that you need to run compiled DLLs
- IKVM.Maven.Sdk package provides MSBuild integration to use <MavenReference> (like IKVMc, dependencies resolution and etc)
- org.apache.opennlp:opennlp-tools is actually a reference to the maven package that we want to recompile.
That is all you need to get started using Maven dependencies from .NET Core!
P.S. If something co wrong, just check that run build on Windows and Maven package compiled using JDK 8. JDK version (Build-Jdk-Spec) you can find in the manifest inside of the JAR file, do not confuse it with Bundle-RequiredExecutionEnvironment!
Build-Jdk-Spec: 11 Bundle-RequiredExecutionEnvironment: JavaSE-1.8