Encountered in the work of the docking Java interface, involving Java encryption or signature problems,. NET cannot be real. Edit the Java code as a DLL to a. NET call
Note: This is only done with simple Java code processing and does not involve complex Java packages
Java File Processing:
The first step: simple Java code
Package com.zht; // C # namespaces Public class TESTAAA { public String returnstring () { return"Hello, zht! " ; }}
Step Two: Java code is compiled into a class file
1: In the Start menu, enter "cmd" in the search box and enter ease;
2: Switch to the Java file storage path;
3: Enter "Javac file name. Java" To compile the Java file into a class file.
Note: The prerequisite is to download the JDK and configure the environment variables.
Step Three: Package the class file
1: In the Start menu, enter "cmd" in the search box and enter ease;
2: Switch to the Java file storage path;
3: Enter "jar CVF file name. jar Directory Name" to convert the directory to a. jar file.
IKVM processing
The first step: Download IKVM Required components to the IKVM official website http://www.ikvm.net/
Ikvmbin-7.2.4630.5.zip (i download the latest version)
Step two: Set the IKVM environment variable
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.
Step three: convert the 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.
Fourth Step: Add the required controls to your 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
Fifth Step: Test
Java classes are used in C # projects in the same way as Java. But the reference to the package uses the syntax using C #
Ikvm:java Code C # calls