About C ++ calling jar package, when creating a virtual machine using jni_createjavavm call failed to return-1

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.