C # method of calling Java's Jar file (GO)

Source: Internet
Author: User

First, the compiled Java in the class file packaging;

Eclipse or myeclipse the export selection jar. or use the command

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;

Cmd-> to the Java class file directory->jar CVF the name of the jar package to generate. The jar Java classes file name. class

Second, to IKVM official website download IKVM Required Components http://sourceforge.net/projects/ikvm/files/ikvm/

Ikvmbin-0.46.0.1.zip

If you can't download it, you can find it in my library and I've uploaded it to my csdn repository.

Third, set the path

Unzip the Ikvmbin-0.46.0.1.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:d:\com. J2Csharp.dll D:\com. J2csharp.jar

where COM. J2Csharp.dll is the file name of the. dll control that will be generated; Com.J2Csharp.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;

public class J2csharp {public String toString () {return "88888888888";}}

C # form Source code:

Using System; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; Using System.Windows.Forms; using COM; namespace CJTTST {public partial class Form1:form {public Form1 () {InitializeComponent ();}

private void Form1_Load (object sender, EventArgs e) {J2csharp js = new J2csharp (); MessageBox.Show ("" +js.tostring ());}}}

C # method of calling Java's Jar file (GO)

Related Article

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.