How to call a method in a jar file from Visual C ++?

In my project, I have a requirement to call methods in a Jar file using VC ++. Is there a way to call methods inside a jar file from VC ++. If you have sample code, this will help a lot.

Thanks in advance! Arun

+4
source share
2 answers

IKVM.Net ( http://www.ikvm.net ) is a .NET implementation of the Java libraries, which is actually not the way you want, but it includes a command line tool called ikvmc (see http: // sourceforge .net / apps / mediawiki / ikvm / index.php? title = Ikvmc ), which converts java byte code to .Net IL code and creates a .Net DLL assembly. I have successfully used this to translate the Java library into an assembly that I included in a C # project.

+1
source

If you use C ++ as the target language, you should use JNI ( http://java.sun.com/docs/books/jni/ ). JNI defines an interface for exchanging data and method calls from / to Java and native code. Simply write the JNI wrapper for a class that contains methods that return and accept simple input parameters (these are native types, without a collection, without arrays). When methods are associated with classes, collections, arrays, etc., it can quickly become cumbersome to manually write a JNI wrapper. This article provides a good overview: http://java.sys-con.com/node/45840 . In this case, you can evaluate a wrapper generator such as GIWS: http://www.scilab.org/products/other/giws .

If you use the .NET environment as the target platform, then IKVM is one option. However, when we had to do this for the present project, we preferred JNBridge, and we successfully managed this (commercial) tool. We did not value IKVM for business reasons: our client only wanted officially supported middleware.

+1
source

Source: https://habr.com/ru/post/1345040/


All Articles