Reputation: 1857
I am trying to make this JNI example works. I am able to compile all the files but I can not launch the executable because of this error :
./TEST: error while loading shared libraries: libjvm.so: cannot open shared object file: No such file or directory
I have checked all the paths, the compilation goes without errors...
Now I think that is linked with my operating system (OpenSuse) or my java version :
I am running java 1.7 and the code use the JVM 1.6 (vm_args.version = JNI_VERSION_1_6;
).. and JNI_VERSION_1_7 does not seem to exist.
Upvotes: 5
Views: 12207
Reputation: 1857
I found a very good example, one of the best on the web I guess, because the author wrote down the paths of each file he uses : Tutorial
I still had a library problem so here is how I managed to get all working :
{ const_cast<char*>("-Djava.class.path=PATH_TO_JAVA_CLASS"), NULL }
$ javac Main.java
.
libjvm.so
on your computer. Once you have
found it, edit the lib path as follows : $ LIBPATH=PATH_TO_LIBJVM.SO
(for me it was in /usr/lib/jvm/java-1.7.0-openjdk-1.7.0/jre/lib/amd64/server
)
$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${LIBPATH}
Now you just have to compile the main.cc file. I had a problem because jni.h
was not found:
a. Find jni.h
(for me /usr/lib/jvm/java-1.7.0-openjdk-1.7.0/include/
)
b. If you have a problem with jni_md.h
, create a symbolic link of jni_md.h
in the same folder of jni.h
c. Compile as follows :
$ g++ -Wall main.cc -I/PATH_TO_jni.h -L${LIBPATH} -ljvm
./a.out
Hello, world!
Hello, Java!
Upvotes: 4