Recently I discovered IKVM.NET, which includes a Java to .NET cross-compilation tool.  This project is mature and has been actively developed by Jeroen Frijters for 10 years.

The following previous articles describe demonstration applications that combine the Prolog and Java programming languages to implement rule-based programs:

I was able to port both the Hurricane Poker and News Goggles demonstration applications to native .NET applications.

Using the IKVMC tool from IKVM.NET, I was able to cross-compile the tuProlog Java Application Archive (2p.jar) into a .NET classlibrary (alice.tuprolog.dll). This was as simple as running the following Windows batch script after downloading the IKVM.NET software.  Note that I chose the destination DLL assembly name to match the root package name for the Java classes in the tuProlog library.  This allows for automatic run-time location and loading of the resulting .NET classlibrary:

@echo off

set TUPROLOG_VERSION=2.5.0
set JAR_FILE=2p.jar
set ASSEMBLY_NAME=alice.tuprolog
set DLL_FILE=%ASSEMBLY_NAME%.dll

set IKVM_HOME=C:\RRutt\UTIL\ikvm-7.0.4335.0
set IKVMC="%IKVM_HOME%\bin\ikvmc.exe"

set IKVMC_OPTIONS=-assembly:%ASSEMBLY_NAME% -version:%TUPROLOG_VERSION%.0

pushd ..\lib
cd

echo Compiling %JAR_FILE% to %DLL_FILE% ...

%IKVMC% %IKVMC_OPTIONS% %JAR_FILE% -out:%DLL_FILE%

popd
cd

echo Done..

pause

Here is the resulting output of that script. Several warnings appeared related to the Java Debug Interface (JDI). I simply ignored these since I do not plan to do any breakpoint debugging within the tuProlog classes from the .NET environment. I have not encountered any problems with this approach.

C:\Users\Richard Rutt\github\NewsGogglesDotNet\lib
Compiling 2p.jar to alice.tuprolog.dll ...
Warning IKVMC0100: class "com.sun.jdi.event.EventSet" not found
Warning IKVMC0100: class "com.sun.jdi.event.EventIterator" not found
Warning IKVMC0100: class "com.sun.jdi.event.Event" not found
Warning IKVMC0100: class "com.sun.jdi.event.MethodEntryEvent" not found
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "javassist.util.HotSwapper$1.run()V"
    ("com.sun.jdi.event.EventSet")
Warning IKVMC0100: class "com.sun.jdi.VirtualMachine" not found
Warning IKVMC0100: class "com.sun.jdi.request.MethodEntryRequest" not found
Warning IKVMC0100: class "com.sun.jdi.connect.Connector" not found
Warning IKVMC0100: class "com.sun.jdi.connect.AttachingConnector" not found
Warning IKVMC0100: class "com.sun.jdi.connect.Connector$Argument" not found
Warning IKVMC0100: class "com.sun.jdi.request.EventRequestManager" not found
Warning IKVMC0100: class "com.sun.jdi.Bootstrap" not found
Warning IKVMC0100: class "com.sun.jdi.VirtualMachineManager" not found
Warning IKVMC0100: class "com.sun.jdi.request.EventRequest" not found
Warning IKVMC0100: class "com.sun.jdi.ReferenceType" not found
Warning IKVMC0100: class "com.sun.jdi.event.EventQueue" not found
Warning IKVMC0100: class "com.sun.jdi.connect.IllegalConnectorArgumentsException" not found
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "javassist.util.HotSwapper.(Ljava.lang.String;)V"
    ("com.sun.jdi.connect.AttachingConnector")
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "javassist.util.HotSwapper.findConnector(Ljava.lang.String;
)Lcom.sun.jdi.connect.Connector;"
    ("com.sun.jdi.Bootstrap")
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "javassist.util.HotSwapper.methodEntryRequests(Lcom.sun.jdi
.request.EventRequestManager;Ljava.lang.String;)Lcom.sun.jdi.request.MethodEntryRequest;"
    ("com.sun.jdi.request.EventRequestManager")
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "javassist.util.HotSwapper.deleteEventRequest(Lcom.sun.jdi.
request.EventRequestManager;Lcom.sun.jdi.request.MethodEntryRequest;)V"
    ("com.sun.jdi.request.EventRequestManager")
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "javassist.util.HotSwapper.toRefType(Ljava.lang.String;)Lco
m.sun.jdi.ReferenceType;"
    ("com.sun.jdi.VirtualMachine")
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "javassist.util.HotSwapper.reload2(Ljava.util.Map;Ljava.lan
g.String;)V"
    ("com.sun.jdi.request.MethodEntryRequest")
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "javassist.util.HotSwapper.waitEvent()Lcom.sun.jdi.event.Ev
entSet;"
    ("com.sun.jdi.VirtualMachine")
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "javassist.util.HotSwapper.hotswap()V"
    ("com.sun.jdi.VirtualMachine")
C:\Users\Richard Rutt\github\NewsGogglesDotNet\scripts
Done..
Press any key to continue . . .

Within my Microsoft Visual Studio solution, I included the generated alice.tuprolog.dll as well as the IKVM.OpenJDK.Core.dll and IKVM.Runtime.dll supplied with the IKVM.NET download.

I then copied my own Java source code to C# source files and manually adapted them to compile in Visual Studio.  Since Java and C# are related languages, this did not require too much effort.

Here is how the HurricanePokerDotNet solution appears in a Visual Studio session:

Hurricane Poker Dot Net as seen in Visual Studio

The two converted applications are available as open source on GitHub.com at the following locations:

For directly cloning the repositories here are the corresponding links:

  • git://github.com/rrutt/HurricanePokerDotNet.git
  • git://github.com/rrutt/NewsGogglesDotNet.git
Advertisements