Why can't I build up a VM when calling JNI_CreateJavaVM?

Hello,everyone,I got a new question,I want to call java in linux redhat 7.3,but it is strange that I failed, though my code seems quite right,please :
#include "jni.h"
#include "dlfcn.h"
#include "iostream.h"
#include "string.h"
#define MAX_PATH 266
typedef jint (* JNI_CREATEJAVAVM)(JavaVM **pvm, void ** penv, void *args);
JavaVM *jvm;
main()
     char szJvm[MAX_PATH]="/usr/java/j2re1.4.0_01/lib/i386/client/libjvm.so";
//I will load libjvm.so with dlopen later
//to receive JreDir
     jclass cls;
jmethodID mid;
     int result;
     JavaVMInitArgs vm_args;
     JavaVMOption options[2];
     jint ret = -1;
     void *hLib;
     char *error=0;
     JNI_CREATEJAVAVM pfCreateJavaVM = 0;
     JNIEnv *env;
     hLib = dlopen(szJvm,RTLD_LAZY);
     if(hLib == 0)
          cout<<"Can not load library libjvm.so of Jre!"<<endl;
          return false;
     else
     cout<<"libjvm.so has been loaded in"<<endl;
     options[0].optionString = "-Djava.compiler=NONE";
     options[1].optionString = "-Djava.class.path=.";
     vm_args.version = JNI_VERSION_1_4;
     vm_args.options = options;
     vm_args.nOptions = 2; //element number of options[4]
     vm_args.ignoreUnrecognized = true;
     /*Create Java VM*/
     pfCreateJavaVM=(JNI_CREATEJAVAVM)dlsym(hLib, "JNI_CreateJavaVM");
     error=dlerror();
     if(error) //error
          //Can't Get JNI_CreatJavaVM address
          cout<<"Can not find JNI_CreatJavaVM function in libjvm.so"<<endl;
          return false;
     else
          //jvm receive the VM being created
          //env is the environment which contains all methods of java class
          ret = (*pfCreateJavaVM)(&jvm,(void**)&env,&vm_args);
     if (ret < 0)
          //failed to create VM
cout<<"Can not create Java VM"<<endl;
return false;
     else
     cout<<"Virtual machine has been set up"<<endl;
And I compile it like this:
g++ Send.cpp -rdynamic -ldl
Then when I run it: ./a.out
it shows error message:
libjvm.so has been loaded in
Error occurred during initialization of VM
Unable to load native library: libjvm.so: cannot open shared object file: No
such file or directory
I don't know what has happened.Help me please,thank you!

Asimov,
I have worked with JNI on OS/2 and all I can suggest is the following points...
Hello,everyone,I got a new question,I want to call
java in linux redhat 7.3,but it is strange that I
failed, though my code seems quite right,please :
#include "jni.h"
#include "dlfcn.h"
#include "iostream.h"
#include "string.h"
#define MAX_PATH 266Make this "#define MAX_PATH 1024". My code would not work with this path set to anything else. It may be OS/2 related, but try this anyway.
>
typedef jint (* JNI_CREATEJAVAVM)(JavaVM **pvm, void
** penv, void *args);
JavaVM *jvm;
main()
char
szJvm[MAX_PATH]="/usr/java/j2re1.4.0_01/lib/i386/clien
/libjvm.so";
//I will load libjvm.so with dlopen later
//to receive JreDir
     jclass cls;
jmethodID mid;
     int result;
     JavaVMInitArgs vm_args;
     JavaVMOption options[2];
     jint ret = -1;
     void *hLib;
     char *error=0;
     JNI_CREATEJAVAVM pfCreateJavaVM = 0;
     JNIEnv *env;
     hLib = dlopen(szJvm,RTLD_LAZY);
     if(hLib == 0)
cout<<"Can not load library libjvm.so of
f Jre!"<<endl;
          return false;
     else
     cout<<"libjvm.so has been loaded in"<<endl;
     options[0].optionString = "-Djava.compiler=NONE";
     options[1].optionString = "-Djava.class.path=.";
     vm_args.version = JNI_VERSION_1_4;
     vm_args.options = options;
vm_args.nOptions = 2; //element number of
options[4]
     vm_args.ignoreUnrecognized = true;
     /*Create Java VM*/
     You have configured some 'user' options here but you must get the 'system arguments' for the JVM also.
Make a call to 'JNI_GetDefaultJavaVMInitArgs( &vm_args )', then pass 'vm_args' into your JNI_CREATEJAVAVM function later.
pfCreateJavaVM=(JNI_CREATEJAVAVM)dlsym(hLib,
, "JNI_CreateJavaVM");
     error=dlerror();
     if(error) //error
          //Can't Get JNI_CreatJavaVM address
cout<<"Can not find JNI_CreatJavaVM function in
n libjvm.so"<<endl;
          return false;
     else
          //jvm receive the VM being created
//env is the environment which contains all methods
s of java class
ret =
= (*pfCreateJavaVM)(&jvm,(void**)&env,&vm_args);
     if (ret < 0)
          //failed to create VM
cout<<"Can not create Java VM"<<endl;
return false;
     else
     cout<<"Virtual machine has been set up"<<endl;
And I compile it like this:
g++ Send.cpp -rdynamic -ldl
Then when I run it: ./a.out
it shows error message:
libjvm.so has been loaded in
Error occurred during initialization of VM
Unable to load native library: libjvm.so: cannot
t open shared object file: No
such file or directory
I don't know what has happened.Help me please,thank
you!
Try those small things and let me know what it returns.
Bryan Galvin.
Software Engineer.

Similar Messages

  • Why can't I connect to iTunes Store when I try to purchase an application?

    Why can't I connect to iTunes Store when I try to purchase an application?

    Hi marlonwanawan,
    If you are having issues connecting to the iTunes Store, you may find the following article helpful:
    Apple Support: Can't connect to the iTunes Store
    http://support.apple.com/kb/ts1368
    Regards,
    - Brenden

  • Why can't i connect to itunes store when i make purchases from apple?

    why can't i connect to itunes store when i make purchases from apple?

    Read http://support.apple.com/kb/TS1368

  • Why can't I hear the phone ring when I call somebody, but if I put the speaker on it works

    Why can't I hear the phone ring when I call somebody, but if I put the speaker on I can hear the ringing?

    Don't jump all the way to restoring just yet.  Check to make sure there's nothing in the headphone jack, and nothing covering the microphones (including the noise cancelling microphone at the top next to the headset jack)
    1. Restart the device. http://support.apple.com/kb/ht1430
    2. Reset the device. (Same article as above.)
    3. Restore from backup. http://support.apple.com/kb/ht1766 (If you don't have a backup, make one now, then skip to the next step.)
    4. Restore as new device. http://support.apple.com/kb/HT4137  For this step, do not re-download ANYTHING, and do not sign into your Apple ID.
    Test the issue after each step.  If the last one does not resolve the issue, it is likely a hardware problem.

  • Why can't I update any apps? When I hit update it gives me an old id. But in settings my new id is totally set and verified. How cam I make the change in App Store?

    Why can't I update any apps? When I hit update it gives me an old id. But in settings my new id is totally set and verified. How cam I make the change in App Store?

    App purchases are permanently tied to the ID with which they were purchased. They cannot be transferred to a new ID.
    You will have to enter the password for that ID or delete the apps and re-purchase them with the new one.
    ~Lyssa

  • HT1695 Why can't I connect to the Internet when I not at home

    Why can't I connect to the Internet when I'm not home

    If you do not have an iPad with 3G cellular service, you can only connect to the internet when you have access to Wifi.  Wifi is not available everywhere, but there are places that do offer free Wifi service, such as Starbucks, Panera Bread, the Airport, etc.  When you are at a location which offers free Wifi access, you have to join their network, which is usuall nothing more than touching a connect option that should automatically pop up, when you open Safari on your ipad. 

  • HT1414 Why can I not text or make and revive calls

    Why can I not text or make and revive calls on my iPhone 4

    Usually cuz its locked to a network other then the SIM's. Did you swap SIMs today? Or it's not seated properly. Take it out and reinsert carefully.

  • TS4079 Why can't I get Siri to make phone calls

    Why can't I get Siri to make phone called for me?

    Sorry but when they made siri it was with iPad 3 you see I have an ipad 2 aswell and I thought that siri wasn't working then I too king it back to Argos and they told me that siri isn't supported on the iPad 2 only ipad 3 and newer

  • Why can I not set a member attribute when there is only one child below the member?

    Why can I not set a member attribute when there is only one child below the member?The "member attribute" tab on the properties window of App Manager is grayed out. What am I forgetting?TIA,Craig Wahlmeier

    Most likely because Essbase is creating an implicit share relationship between the two members, which is causing the association tab to be grayed out. Tag the parent member with the "Never Share" attribute and see if that fixes the problem.Regards,Jade-----------------------------------Jade ColeSenior Business Intelligence ConsultantClarity [email protected]

  • Why can I not negotiate a loyalty discount when upgrading

    Why can no one I have spoken to recently offer me a loyalty discount? I have been with TMobile for many years but this now seems to be disguarded. I can get equally good offers or better elsewhere!

    Why the hell should you get a loyalty discount for? I shop regularly at Carphone Warehouse. I catch Arriva buses regularly, have breakfast in McDonald's regularly and I also use Skyline Taxis regularly. I pay the going rate. If I don't like the price I go elsewhere. If you don't like the EE prices them I'm sure you can do the same!

  • Why can't iPod connect to wifi network when iPad and Macbook can?

    Why can't my iPod connect to wifi network when iPad and Macbook both can? Connected in the past, but not for the past week.

    - Reset the iPOd. Nothing will be lost.
    Reset iPod touch:  Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears
    - Power off andthen back on the router
    - Power off and then back on the router.
    - Reset network settings>Settings>General>Reset>Reset Network Settings
    iOS: Troubleshooting Wi-Fi networks and connections

  • HT1918 Why can't I buy credit on games when I know my card has the free charge available?

    Why can't I buy credit I get contact iTunes support I know I have funds on my card ?

    We are fellow users, we won't know why, if you haven't already done so then you contact iTunes Support then you can do so via this link and ask them why the message is appearing : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Why can't siri find me in Haiti when the Map app can?

    I know everyone is asking the same questions but I was just wondering, why can't siri find me outside the US (Haiti) when the map application clearly can and has all the info and restaurants, etc. Also Siri can"t seem to be able to dial 8 digits numbers ( 509-xxxx-xxxx). Anyhow, I just want to know if this is going to be permanent or will there be an update to fix it.
    Thank you.

    Because currently, location based search, using SiRi, only works in the US. More countries to be added this year.

  • Why can't Safari connect to free wifi when other browsers can?

    When  trying to use free WIFI in hotels, the connection requires opening browser  and then the hotel log in screen pops up for me to log in (room number or sometimes just to say "agree")
    Safari does not work!
    I set my network connection to Automatic
    The WIFI address I want shows up so I  can select and the button turns green,next to "Wifi" in Network Preference
    But when I then launch Safari, nothing  ... I cannot log into the hotel's network
    Yet if i launch Chrome or FireFox, immediately the hotel's window pops up  and then I am fully on the Internet (and can use Safari
    I have no firewall or such , so why can't Safari do what other browsers can?

    equinez wrote:
    SNIP...
    I hope it's a simple fix as I'm not very computer "smart"
    Lori
    <Email Edited By Host>
    you can learn a VERY valuable lesson from this question... NEVER publish your email address in public forums of any kind - FaceBook, Google+, chats, etc. - these places are low hanging fruit for nefarious characters - ÇÇÇ

  • Why can't I buy the lollipop hammer when my apple acct is up to date?

    Why can't I purchase the lollipop hammer in Candy Crush if my acct is up to date?

    Nobody here can even begin to hazard a guess with the limited amount of information that you provided. Contact iTunes Store Support and ask them.
    https://expresslane.apple.com/Issues.action

Maybe you are looking for

  • How i can print on bouth side???hp officejet6​500aplus

    i need print book on bouth side, but in my manuel i don't have any information..so please help me to find how i can print on bouth side automaticaly???

  • What are the conditions to use hotpatch

    Hi Experts. What is the criteria for deciding whether hotpatch can be used? From what I gather, the following is used as a guide: the patch is small it doesn't update any executable Is there anything else I should check? Thanks in advance, DA.

  • How to run diagnostic

    Hi I know this is a simple tasks but for me its not. how to obtain this task: Please upload the Diagnostic: Apps Check output for the process execution product GME to check the file versions you are on. we are using ebs r12.1.2 with 11.1.0.7 database

  • Distribution & collection via Email

    Hi friends, Can anyone tell steps to configure email setup - at server/backend, for distributing inputschedules or reports using distribution & collection mechanism. While distributing via email getting below errors: Error messages: 1. Error download

  • Epson 1400

    We are looking to buy a good photo printer for use with iPhoto '08. The Epson Stylus Photo 1400 has great reviews on several sites including Mac World, but the review states it "lacks integration with iPhoto." Can anyone explain what this means? Anyb