How to use IKVM to integrate Java to DotNet
Using Ja.Net to integrate Java and DotNet(c#): Basic
Using Ja.Net to integrate Java and DotNet(c#): Class and Type
Using Ja.Net to integrate Java and DotNet(c#): More detailed basic issues
Using Ja.Net to integrate Java and DotNet(c#): Encoding and Properties
Using Ja.Net to integrate Java and DotNet(c#): Class implementing and inheriting
Using Ja.Net to integrate Java and DotNet(c#): Assemblies in Java Source code
Using Ja.Net to integrate Java and DotNet(c#): IO in Java and DotNet
That’s definitely good news for SQLReport that we can integrate Java binary into DotNet platform, so that the two platforms can use the same source code.
There are two toolkit can do the integration, the first is Ja.Net and the second one is IKVM.NET. After a short time investigation, I decided to use IKVM.NET to do the integration.
Before we do the real work, I wonder whether the DotNet could implement the interface defined in the Java source code and whether the Java source code could use the implementation from DotNet.
Let’s do a test.
The first, you must download the newest version of IKVM from the site.
And I write one interface class and one class to customer the interface in Java source code, the implementation of the interface will be in DotNet source code, here is the Java source code:
package testlib;
public interface IInterface {
public String testString();
}
//---------
package testlib;
public class TestUsingInterface {
private IInterface m_interface=null;
public TestUsingInterface(IInterface a) {
this.m_interface=a;
}
public String DoWork()
{
return null==this.m_interface?"NULL Interface":this.m_interface.testString();
}
}
Compile them and package them into one jar file.
C:\Develop\JavaProjects\TestLib\classes>%JDK5%/bin/jar -cvf testlib.jar .
Using IKVM compiler to convert the jar file into a new DLL which can be used by DotNet source code:
c:\tools\ikvm.bin\ikvmc -target:library testlib.jar
The output file is “testlib.dll”.
Open visual studio, and create a new console application, add “testlib.dll” and “IKVM.OpenJDK.core.dll” as references.
Edit the default “program.cs” as :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestIKvmLib
{
class AInstance : testlib.IInterface
{
#region Itestinterface Members
public string testString()
{
return "AInstance";
}
#endregion
}
class Program
{
static void Main(string[] args)
{
testlib.TestUsingInterface a = new testlib.TestUsingInterface(new AInstance());
System.Console.WriteLine(a.DoWork());
System.Console.Read();
}
}
}
Compile the DotNet source code, and then run it,Yep, it works.
The next plan for SQLReport is :
- Expression parser and evaluator will be hold in Java.
- DataSet generation and morphs will be hold in Java.
- Basic model defined in Java source code.
- XML handling is in Java and DotNet source code pass the content of XML files to the Java XML parser.
- Report showing and Charts generation will be hold in DotNet using the DataSet generated by Java.