Beruflich Dokumente
Kultur Dokumente
home
articles
quick answers
discussions
1 Member 10878646
features
Browse Code
Bugs / Suggestions
Stats
Next
Rate:
Revisions
Alternatives
Comments (33)
View this article's
Workspace
Fork this Workspace
Share
Sign out
community
help
Article
306
Is your email address OK? You are signed up for our newsletters but your email
address is either unconfirmed, or has not been reconfirmed in a long time. Please
click here to have a confirmation email sent so we can confirm your email address
and start sending you newsletters again. Alternatively, you can update your subscriptions.
Introduction
Suppose you have been asked to migrate an existing multi-tier application to .NET where the
business layer is written in Java. Normally you would have no option but to recode and port the
entire application to any .NET language (e.g. C#). However this is where IKVM.NET comes to the
rescue.
About Article
IKVM.NET is an open source
implementation of Java for
Mono /Microsoft .NET
Framework and makes it
possible both to develop
.NET applications in Java,
and to use existing Java
APIs and libraries in
applications written in any
.NET language.
Type
Article
Licence
CPOL
First Posted
24 Mar 2006
Views
87,712
Downloads
2,072
Bookmarked
53 times
C# Windows Java
SE .NET
Visual-Studio Dev , +
IKVM.NET is an open source implementation of Java for Mono /Microsoft .NET Framework and
makes it possible both to develop .NET applications in Java, and to use existing Java API's and
libraries in applications written in any .NET language. It is written in C# and the executables,
documentation and source code can be downloaded from here.
IKVM.NET consists of the following three main parts:
1. A Java Virtual Machine implemented in .NET
2. A .NET implementation of the Java class libraries
3. Tools that enable Java and .NET interoperability
However before we get any further into this topic, lets discuss about few of the main components
of the IKVM.NET package which we would be using later in this article.
IKVM.Runtime.dll: The VM runtime and all supporting code containing the byte code JIT
compiler/verifier, object model remapping infrastructure and the managed .NET reimplementations of the native methods in Classpath.
IKVM.GNU.Classpath.dll: Compiled version of GNU Classpath, the Free Software
Foundation's implementation of the Java class libraries, plus some additional IKVM.NET
specific code.
ikvm.exe: Starter executable, comparable to java.exe ("dynamic mode").
ikvmc.exe: Static compiler. Used to compile Java classes and jars into a .NET assembly
("static mode").
Now back to our problem of migrating the existing Java business classes so that they can be
accessed by the newly proposed .NET application. We would also like to use the various existing
Java API and libraries in our .NET application. Lets start by doing just that.
Setting Up IKVM.NET
Download the binary distribution from the sourceforge site and unzip the contents to C:\ikvm (or
X:\ikvm where X is your drive). You would find the ikvm executables and DLLs in the C:\ikvm\bin
http://www.codeproject.com/Articles/13549/Using-Java-Classes-in-your-NET-Application
Related Articles
Skypekit.NET
IKVM.NET in Details
Embedding .NET Controls in
Java
Using the Java Native Interface
in C#
Building a Distributed Object
System with .NET and J2EE
Using IIOP.NET
Introduction to .NET
Hosting WPF Content in a Java
Application
.NET Platform Invoke Paradigm
in Java (J/Invoke)
How to consume an ASP.NET
webservice from Java via SOAP
The Interface Construct in C#
A Smart Card Framework for
.NET
DotNetMatrix: Simple Matrix
Library for .NET
Accessing an EJB from .NET
Using IIOP.NET: an Example
Using C#, Java Webservices and
JMS together
1/6
19/6/2014
If your system is operating correctly, you should see the following output:
usage: ikvm [-options] <class> [args...] (to execute a class) or ikvm -jar [-options] <jarfile> [args...]
(to execute a jar file)
For Linux based systems, the setup is similar as above. This is all you need to do for running the
demo application.
Related Research
Our Java class is very simple. It has four functions for add, subtract, multiply and divide that take
two double values and return a result. Our objective is to access these functions through our C#
application. Compile the above Java file to get the JavaToNet.class. We will use this Java class file
to generate the .NET DLL to be referenced in our C# program.
Copy the above Java class file (JavaToNet.class) to the C:\ikvm\bin directory. Now run the
following command:
This would create the JavaToNet.dll from the JavaToNet.class file. There are other command line
option for ikvmc.exe. For example: i
kvmc target:exe javaToNet.class would create
an EXE and not a DLL. You can get all the options by typing ikvmc in the command line.
http://www.codeproject.com/Articles/13549/Using-Java-Classes-in-your-NET-Application
2/6
19/6/2014
3. Add the following DLLs as references to the project. Both DLLs are present in the
C:\ikvm\bin folder.
JavaToNet.dll
IKVM.GNU.Classpath.dll
4. Add the following code to the button click event of the Calculate button:
Collapse | Copy Code
6. Add the following code to the button click event of the Time Zone button.
Collapse | Copy Code
7. Compile and run the application. The C# application would now call the A
ddNumbers(),
SubNumbers(), MulNumbers() and DivNumbers() functions present in the
JavaToNet.dll and return the result.
8. Click on the Time Zone button. The application accesses the j
ava.util.TimeZone class
and displays the exact time zone of the place.
http://www.codeproject.com/Articles/13549/Using-Java-Classes-in-your-NET-Application
3/6
19/6/2014
Conclusion
Since these methods had originally been written in Java, IKVM.NET provides us an easy and viable
way to access those classes and methods from a .NET application. Similarly as shown above in the
Time Zone example, you can access most of the existing Java packages (e.g. java.io, java.util, etc.)
and use them in your application.
However there are certain drawbacks. IKVM.NET, while still being actively developed, has limited
support for AWT classes and hence porting Java GUI can be ruled out at present. Also some of
the default Java classes are still being ported so you might not get all the functionalities you
require. Also if your application depends on the exact Java class loading semantics, you might
have to modify it to suit your needs.
History
03-25-06 Initial publication
License
This article, along with any associated source code and files, is licensed under The Code Project
Open License (CPOL)
Chayan
Web Developer
India
Chayan Ray has been working as a Technical Consultant in a CMM level 5 company in India. His
technical domain includes ASP.NET, C#, PHP, Perl, Cold Fusion, MySQL and MSSQL 2000.
Article Top
http://www.codeproject.com/Articles/13549/Using-Java-Classes-in-your-NET-Application
4/6
19/6/2014
Noise Medium
Layout Normal
Go
Per page 25
Update
First Prev Next
Missing file
Shailenderrajput
MrKyaw
sonam502173
2-Jan-13 8:24
sonam502173
2-Jan-13 8:23
sonam502173
2-Jan-13 8:22
Member 4559750
NarVish
25-May-12 8:29
Thank you...
rajendranmca2008
25-Oct-11 2:42
Thanks
sanya.fesak
22-Sep-11 0:12
majed.idrees
Nguyen_Chuong
21-Feb-11 9:54
dummy programmer24
1-Dec-10 20:13
16-Jun-12 8:37
16-Apr-11 21:20
2-Dec-10 3:08
dummy programmer24
2-Dec-10 9:11
DilushaM
IthilienX
21-Jan-13 2:24
Chayan
My vote of 5
3-Feb-14 3:36
9-Jul-10 14:04
26-Oct-08 19:14
Rini Jackson
14-Mar-12 10:20
Nitin Sawant
30-Nov-12 5:40
MHSrinivasan
Askalo
Yeast27
devesh.kumar
Vitaly Shelest
http://www.codeproject.com/Articles/13549/Using-Java-Classes-in-your-NET-Application
19-Jun-08 5:15
6-Jul-07 10:37
25-Sep-06 8:04
7-Jul-06 4:49
22-Jun-06 8:02
5/6
19/6/2014
News
surjithpk
12-Apr-06 7:13
Chayan
12-Apr-06 10:12
Question
Refresh
Bug
Answer
Joke
1 2 Next
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Permalink | Advertise | Privacy | Mobile
Web02 | 2.8.140618.1 | Last Updated 24 Mar 2006
http://www.codeproject.com/Articles/13549/Using-Java-Classes-in-your-NET-Application
6/6