How to call the jar library file generated by Java in C #

Source: Internet
Author: User
1. Package the compiled class files in Java. The package command jar is used to package all the class folders in a directory. The command used is jar CVF test. jar-c com /. test. jar is the jar package to be generated; COM /. for the folder under the specified current directory, which includes subfolders and class files; 2. Download the components required by ikvm http://www.ikvm.net/ikvm-0.42.0.3.zip ikvmbin-0.42.0.3.zip openjdk6-b16-stripped.zip from the ikvm official website; 3. Set the path to decompress ikvm-0.42.0.3.zip, add % ikvm_home %/bin to path. Here % ikvm_home % refers to the main directory of ikvm after decompression. 4. Convert the Java jar package. dll Control Command: ikvmc-out: ikvm. DLL test. jar, where ikvm. DLL is. dll Control File Name; test. jar is the previously packaged jar package. 5. Add the required controls to the C # project. 1. Create a new C # project #. net project, first add the required 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. the DLL file will be generated before. load the DLL file to the C # project. 6. Test the Java class used in the C # project. The method is the same as that in Java. However, the C # syntax using is used for package reference. Source code : Java source Code : 1 Package Com. zht;
2 // Java class to be called
3 Public Class Test {
4 // Java method to be called
5 Public String returnstring (){
6 Return "Hello, zht! ";
7 }
8 } C # form source code: 1 Using System;
2 Using System. Collections. Generic;
3 Using System. componentmodel;
4 Using System. Data;
5 Using System. drawing;
6 Using System. LINQ;
7 Using System. text;
8 Using System. Windows. forms;
9 Using Com. zht;
10
11 Namespace Kivmtest
12 {
13 Public Partial Class Form1: Form
14 {
15 Public Form1 ()
16 {
17 Initializecomponent ();
18 }
19
20 Private Void Form1_load ( Object Sender, eventargs E)
21 {
22 Test T = New Test ();
23 String STR = T. returnstring ();
24 MessageBox. Show (STR );
25 }
26 }
27 }

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.