Ikvm:java Code C # calls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.