Goal
Let's say, we have a large C++ application that does some large things, that are good to be done using C++. But, there are a plenty of logic, that we'd prefer to run on JVM.
Issue
To test approach described above, I created small C++ project using CLion. Scenario is:
Build (automated by CMake):
- link code snippet with
$JAVA_HOME/lib/jvm.lib
- copy all DLLs from
$JAVA_HOME
to the directory with just createdexe
Run:
- create embedded JVM
- invoke static method hosted by this JVM
I tried Visual Studio 2019 Community and MinGW64 (x86_64-8.1.0-posix-seh-rt_v6-rev0) toolchains and both led to identical results.
The best results I've got with OpenJDK (jdk-14.0.2):
Error occurred during initialization of VM
Failed setting boot class path.
Oracle JDK 1.8 has shown a bit different failure:
Error occurred during initialization of VM
Unable to load native library: Can't find dependent libraries
I also tried different versions from ojdkbuild and the best I get is SEGFAULT at the env->FindClass
invocation.
Questions
- What distribution of JVM is better to use for embedding to C++?
- How to link and distribute it all properly?