Today, when I tested the program, I found that the Program for debugging the available c ++ jar program suddenly encountered a problem and always encountered a problem when creating a Java virtual machine.
When calling the jni_createjavavm function, it always returns-1. I checked it online and said,"
It may be related to a local environment containing multiple virtual machines. When this function is called,-1 is always returned, and the VM creation fails.
The solution is to use loadlibrary and getprocaddress to directly load the jni_createjavavm of the developed JVM.
"
Check whether there are multiple virtual machine environments in the system.
VI lD. So. cache open this file and check libjvm. So. Several results show that there are indeed two
^ @ Libjvm. So ^ @/usr/Java/jdk1.5.0 _ 04/JRE/lib/amd64/Server/libjvm. So ^ @ libjvm. So ^ @/lib/libjvm. So
/Usr/Java/jdk1.5.0 _ 04/JRE/lib/amd64/Server/libjvm. So
/Lib/libjvm. So
According to the previous usage, the so parameter/usr/Java/jdk1.5.0 _ 04/JRE/lib/amd64/Server/libjvm. So is used.
So I tried to delete the/lib/libjvm. So file.
Ldconfig: The above so will be left in LD. So. cache.
Re-debug the C ++ program to drop the jar package.
This is a solution
Specify the so to be loaded in another explanation. You can try it.
Javavmoption options [4];
/* Set initialization parameters */
Options [0]. optionstring = "-djava. compiler = none ";
Options [1]. optionstring = "-djava. Class. Path =...: ../lib/jym. jar: ../lib/codeutil. Jar ";
Options [2]. optionstring = "-djava. Library. Path =/usr/Java/jdk1.5.0 _ 04/JRE/lib/amd64/Server"; // specify the loaded so path
Options [3]. optionstring = "-verbose: none"; // used to track running information
/* Version number setting cannot be missed */
Vm_args.version = jni_version_1_4; // JDK version 1.4
Vm_args.noptions = 4;
Vm_args.options = options;
Vm_args.ignoreunrecognized = jni_true;
Res = jni_createjavavm (& JVM, (void **) & ENV, & vm_args );