C # Method steps for calling jar package (very detailed) _C # Tutorial_Script Home

C # Method steps for calling jar package (very detailed)

Updated: 09:32:56, January 5, 2021 Author: ken, programmer
This article mainly introduces the method and steps of c # calling jar package. It is very detailed through pictures and text, and has certain reference learning value for your study or work. Now let's learn together with the editor

preface

Recently, the project encountered a problem, that is, there is a requirement that the data on the cs side need to be encrypted (using the sm4 encryption method), and the back-end receiving needs to be decrypted. However, the cs side is written by c #, and the back-end is written by java. The results of the encryption methods on both sides will be different. Of course, our team is still not deep in the research of algorithms. Later, I found a way to call the middle C language, but it was still not good. Finally, I found a way to print the java code into jar packages and then convert them into dll for the cs side to call.

The steps are as follows

1、 Package the compiled class file in java; Packaging command JAR

Packaging: You can use commands or tools such as eclipse and idea to directly package [source code will be placed at the end]

2、 Go to the official website of IKVM to download components required by IKVM

www.ikvm.net/

There are a lot of online tutorials that do not mention that the jdk version is related to this. As shown in the figure, it supports version 1.8, which is not compatible with lower versions. If you cannot find this version of ikvm, you can talk to me privately.

3、 Set the path to decompress ikvm-8.1.5717.0.zip. You can set the path of IKVM_HOME to the environment variable, or you can directly use the fixed path to configure it. Here, I directly configure the complete path

4、 Commands used to convert java jar packages into. dll controls: ikvmc - target: library xxx.jar and ikvmc - target: library - reference: need to reference A.dll - reference: need to reference B.dll main. jar

The former command is to print the jar into dll, while the latter is to add the dll package that needs to be imported externally (the original jar package reference)

Ps: I copy all the jar packages to the bin directory of the ikvm, and use the ikvmc command in the bin directory. If I use idea to import all the lib packages in a directory and import them in modules, I just need to print the main jar package into a dll, and do not need to reference it to the cs. For eclipse, I need to print all the lib packages into a dll. [Here is to see the actual situation, it is better to print them into dll for import] 5. To add the required controls in the C # project, you need to download: ikvm, otherwise an error will be reported

Reference packaged dll

Now you can use it

summary

That's all for this article about c # calling jar package. For more information about c # calling jar package, please search the previous articles of Script Home or continue to browse the following articles. I hope you will support Script Home more in the future!

Related articles

Latest comments