Mar 16

IKVM.NET – Java without installing

Tag: UncategorizedSymon Rottem @ 7:57 pm

Working on the DocBook version of the Castle documentation this weekend I found that to be able to take advantage of the built in syntax highlighting features of the DocBook XSL package I need to use a Java plugin but the XSL processor I’ve been using doesn’t support the plugin. The solution, of course, is to move to a processor that’s Java based but that then means that the build server needs to have a Java runtime installed to execute…or so I thought.

It turns out that there’s this really cool project called IKVM.NET that provides a Java Virtual Machine in .NET that allows you to run Java applications in the .NET Runtime. After some reading and experimenting I managed to get it working, so now I can use that Java based processor without installing Java.

What’s more, this will help with another little problem I’ve been chewing over – the generation of PDFs using Apache FOP. Apache FOP appears to be the most mature Open Source FO processor out there and seems to be the recommended way of converting DocBook into PDF. The kink for me was – you guessed it – it’s another Java package.

Using IKVM can be as simple as executing ikvm.exe in place of Java on the command line. So instead of executing the following…

java -jar myapp.jar

…you can instead use…

ikvm -jar myapp.jar

IKVM also provides utilities for converting Java bytecode to .NET IL which allows you to generate a .DLL from a Java library that can be used directly in a .NET application. Very cool – I recommend having a look if there’s some fantastic Java library out there with no .NET equivalent.

To get all this all you need are a couple of DLLs and executables. Admittedly it’s a little heavy to deploy with your code at 26Mb but it’s nice to know it’s there as an option instead of being forced to install the “official” Java Runtime.

Related Posts