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

To be a good employee leads to be a better employer.

Background

Some time ago, I received a new project, it is definitely a report system which shows data with tables and charts. After a long time discussion, the customers and I made a decision that we should implement this project base on Microsoft DotNet framework, the mainly reason is reducing installation, an windows application is easy to use, no installation, no configuration, no more extra software.

It make me felt very embarrassed, because the SQLReport implemented almost all of those functionalities which customers needed, but SQLReport is based on Java, and I can not use Java Source code and binaries in DotNet framework. I really do not want to write a same report system in C#, it is definitely copy and translate source code from Java to CSharp, who want to do this boring work?

As MS has released two tools for this translation, one tool is Visual J#(VJ#), and another is JLCA. VJ# is not Java, it is a Java-like language and CLI compiler, some Java language feature, i.e. adding references("import"), class searching, have been modified in VJ#. VJ# is really not a Java, it use Java as a mask to produce CLI. And for JLCA, it is a tool to translate a Java source file into VB or C#, it looks good, but not really good, it only supports JDK1.3 syntax, no JDK1.4, let alone JDK1.5.

So MS can not support us to do the transparent programming, I have to find some third-party tool.

The first tool I used is IKVM.Net, it is a amazing tool to convert Jar files into CLI assemblies and provides a small JVM to run those assemblies. I have wrote a article to discuss how to use it. The fatal shortcoming of IKVM.Net is that the tool only support JDK1.4, no annotations, no generic programming, as SQLReport has a lot of generic programmed source code, I have to fall over all of the source code from JDK1.5 to JDK1.4, it is not only a boring work, but also limits the further upgrade of SQLReport, it seems that is not good ideal using IKVM.Net to do the integration. 

Finally, I focused on Ja.Net, another amazing tool to compile Java source code to assemblies, notes that IKVM.Net convert classes to assemblies, but Ja.Net compile it directly.

Preparation

Mainly site of Ja.Net is : http://www.janetdev.org/

Download all source from that site, notes that you should not download the JDDK version, this version does not work in my laptop (Windows XP SP3, JDK1.6), please download one JDK version for you.

The source code of Ja.Net can be check-out by SVN client at: https://janetdev.svn.sourceforge.net/svnroot/janetdev, it is a huge source code package, be patient during downloading, I download almost 1.14G (more than 71,900 files) .
Ja.Net provides the following tools:

  • Javac, a Java language compiler based on Eclipse compiler.
  • Java, a tool to execute Java application.
  • JVM, a embedded JVM based on Apache Harmony. (The term "Harmony" is great in China, I really don't want to make you more confused, ^_^).
  • BAM, a tool to assemble Java byte-code into assemblies.

The Javac which Ja.Net provided can compile Java byte-code (Notes that it is NOT based on the standard Java byte-code specification, it only can be used with Ja.Net java tool) and CLI assemblies, using parameter "-java" to toggle the target.

Notes that the libraries referenced (third-party Jar files/classes) in your source code must be compiled by Ja.Net first, otherwise, you will get a lot of "Class *** not found" errors, this issue take me whole day to testing.

I'd like to test what it can do and can't do in some test cases.


Jeason Zhao (沈胜衣,斛律光) ------雪饮再现,一个人的江湖
我知道我是谁,我是沈胜衣,默默的活着,就像空气。