First, the compiled Java in the class file packaging;
Eclipse or myeclipse the export selection jar. or use the command
For example, all the class folders under a directory are packaged and processed;
Command used: Jar CVF test.jar-c com/.
Where Test.jar is the jar package to be generated; com/. To the specified folder in the current directory, which includes subfolders and class files;
Cmd-> to the Java class file directory->jar CVF the name of the jar package to generate. The jar Java classes file name. class
Second, to IKVM official website download IKVM Required Components http://sourceforge.net/projects/ikvm/files/ikvm/
Ikvmbin-0.46.0.1.zip
If you can't download it, you can find it in my library and I've uploaded it to my csdn repository.
Third, set the path
Unzip the Ikvmbin-0.46.0.1.zip and add the%ikvm_home%\bin to the path. The%ikvm_home% here refers to the IKVM home directory after decompression.
Iv. Converting a Java jar package to a. dll control
Command used: ikvmc-out:d:\com. J2Csharp.dll D:\com. J2csharp.jar
where COM. J2Csharp.dll is the file name of the. dll control that will be generated; Com.J2Csharp.jar is the jar package file that was previously packaged.
V. Adding the required controls to a C # project
1. Create a new C #. NET project, first add the necessary DLLs
%IKVM_HOME%\BIN\IKVM. OpenJDK.Core.dll
%IKVM_HOME%\BIN\IKVM. Runtime.dll
%IKVM_HOME%\BIN\IKVM. Runtime.JNI.dll
2. Add the generated. dll file
To load a previously generated. dll file into a C # project
VI. Testing
Java classes are used in C # projects in the same way as Java. But the reference to the package uses the syntax using C #
Source:
Java source code:
Package com;
public class J2csharp {public String toString () {return "88888888888";}}
C # form Source code:
Using System; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; Using System.Windows.Forms; using COM; namespace CJTTST {public partial class Form1:form {public Form1 () {InitializeComponent ();}
private void Form1_Load (object sender, EventArgs e) {J2csharp js = new J2csharp (); MessageBox.Show ("" +js.tostring ());}}}
C # method of calling Java's Jar file (GO)