简体   繁体   中英

Compile Java project to a native library and create a C/C++ wrapper on top

  1. I am working on a C/C++ project.

  2. I found online some very valuable assets in form of Java libraries that I would like to integrate into my C/C++ project. These are big projects I wouldn't consider porting to C/C++.

  3. I read in a Stackoverflow post that Java code can be compiled to native code, thus one would be able to run a Java project without having a Java Virtual Machine in the middle. I found also that there is even a commercial tool for doing this called ExcelsiorJET thus making me believe even more that this could be a reliable thing.

Taking 1, 2 & 3 into consideration I wondered whether or not, one could take a Java library, compile it into a native library and then create a C or C++ wrapper on top of that library. This means that this way the Java Virtual Machine will not be needed anymore. This way I will get rid of the Java Virtual Machine layer. Could this be possible?

I searched online to see if someone had ever successfully created this kind of a pipeline, but couldn't get to a conclusion...

What I would like to ask is whether or not this pipeline could be possible, at least in theory if there are no online examples of people successfully creating it.

If this is possible could anyone point me in the right direction?

Have a look at JNI and the JVM startup sequence: it's all C/C++ coding at this level.

You can either compile java ahead of time (AOT) or you can call the JVM as if it was a library (this is how executable wrappers like Launch4j work).

One way to simplify Java/C/C++ interfacing is to use IDL. Once you have defined your IDL interface it can be used to generate Java/C/C++ code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM