The method of invoking Java-generated jar library files in C # is to package the compiled Java class file, and package the command jar with the following: Package all the class folders under a directory, and use the command: Jar CVF test.jar-c com/. Where Test.jar is the jar package to be generated; com/. For the specified folder in the current directory, the folder 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 Three, set the path decompression Ikvm-0.42.0.3.zip, and add%ikvm_home%/bin to the path. The%ikvm_home% here refers to the IKVM home directory after decompression. D. Convert the Java JAR package to the command used by the. dll control: 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. Add the required controls in the 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 a generated. dll file to load a previously generated. dll file into a C # project VI. testing uses Java classes in C # projects in the same way as Java. But the reference to the package uses the syntax of the C # using source code: Java source code:1Package com.zht;
2// Java class to invoke
Span style= "COLOR: #008080" >3 public class test {
4 // Java method to invoke
5 public string returnstring () {
6 return "Hello, Zht! ";
7     }
8 } C # form Source code:1Using System;
2Using System.Collections.Generic;
3Using System.ComponentModel;
4Using System.Data;
5Using System.Drawing;
6Using System.Linq;
7Using System.Text;
8Using System.Windows.Forms;
9Using Com.zht;
10
11Namespace Kivmtest
12 {
13PublicPartialClass Form1:form
14 {
15Public Form1 ()
16 {
InitializeComponent ();
18}
19
20Privatevoid Form1_Load (Object sender, EventArgs e)
21 {
Test T = new test ();
The string str = t.returnstring ();
MessageBox.Show (str);
25}
26}
+ }
C # Methods for invoking JAR packages