One, the compiled Java in the class file packaging, Packaging the command jar (or directly using Eclipse packaging is more convenient)
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;
Second, to IKVM official website download IKVM Required Components http://www.ikvm.net/
ikvm-0.42. 0.3. Zip Ikvmbin-0.42. 0.3. Zip openjdk6-b16-stripped. Zip
Third, set the path
Unzip the Ikvm-0.42.0.3.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:ikvm.dll Test.jar
Where IKVM.dll is the file name of the. dll control that will be generated; Test.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.zht; // the Java class to invoke Public class Test { // Java method to invoke public String returnstring () { return "Hello, zht!." ; }}
C # form Source code:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingCom.zht;namespacekivmtest{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidForm1_Load (Objectsender, EventArgs e) {Test T=NewTest (); stringstr =t.returnstring (); MessageBox.Show (str); } }}
Results:
After starting the C # window, a prompt window appears with the following: Hello, zht!
C # calls Java class, Jar package method