1, first you need to IKVM official website download IKVM. http://sourceforge.net/projects/ikvm/files/, it is important to note that if you are using. NET framework2.0, then the latest version of IKVM is not available, you can use the 0.38.0.2 version of
Configure Environment variables: Right click on "Computer", select "Properties", go to "Advanced system Settings", "Advanced" and "Environment variables", add ";D: \program Files\ikvmbin-7.2.4630.5\ikvm-7.2.4630.5\bin", where the first one"; "optional, followed by" D:\Program files\ikvmbin-7.2.4630.5\ikvm-7.2.4630.5 "for your IKVM path. Test: Through "CMD", enter "Ikvmc", enter the following can see a lot of information. 2, next you want to write a simple Java program, the most popular example of online:Package Com.zht;//Java class to invokePublic class Test {//Java method to invokePublic String returnstring () {return "Hello, zht!"; }}3, you want to package the Java program into a JAR file select the project, right-click, select "O (export/export)", select "Java"-"Jar file", after the next, select the class file (or package) you want to package, select "Export generated class files and resources", and then Next, OK.
4. After you use IKVM to compile the jar file into DLL file cmd, enter "Ikvmc-out:e:\hello.dll E:\hello.jar", Ikvmc is the command,-out: The DLL file followed by the output, followed by a space after the jar file. 5. Call DLL file in C # to create a new C # project (either a console program or a WinForm program), add a reference: 1) hello.dll (DLL file you just generated) 2) IKVM.OpenJDK.Core.dll; IKVM. Runtime.dll; IKVM. Runtime.JNI.dll (these three are basic DLL files, other DLL files are added as appropriate)
Import the namespace through the using COM.ZHT. You can create a new test class, and use the methods of that classreturnstring ();The code is as follows:using System;using System.Collections.Generic;using System.Linq;using System.Text;using Com.zht;namespace Dlltest{Class Program {static void Main (string[] args) {Console.WriteLine (New Test ()). Returnstring ());Console.readkey (); } }}Running results such as:
Turn Java code into a C # usable DLL