This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes Cannot start JVM - problem with JNI. Help!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cannot start JVM - problem with JNI. Help!!" Watch "Cannot start JVM - problem with JNI. Help!!" New topic

Cannot start JVM - problem with JNI. Help!!

frankie aranha

Joined: Oct 02, 2001
Posts: 7
Hi,I have below a simple piece of code which tries to start the JVM from C.
This compiles fine(I load all the libraries i need to - libjava,libjvm and libhpi) but when i run it,it does not create the Java VM.I dont understand why it doesn't,my immediate guess is that the classpath argument that i'm providing, is not the one it's looking for.I have my sample code below:
It prints out the classpath that i'm passing to the JNI_Cre...function and also the error number that the function returns.Anybody have any suggestions??
The Code:
#include "/usr/include/jni.h"
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
int success=999;
int status=999;
int ext=999;
int q=0;
int i;
int j;
int f=0;
int ibin;
int a=0;
char * events;
char * tests;
int ievents,itests;
int k=0;
int outcount=0,count=0;
char * bin; //to remove
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[3];
int nbOptions;
jint res;
jclass myJavaClass;
jobject javaGUI;
jmethodID constructorID;
char *classPath, *libraryPath;
classPath = malloc(500);

libraryPath = malloc(500);
strcpy(libraryPath, "/home/frankie/Java/JNI/Ex3");
vm_args.version = JNI_VERSION_1_2;
/* Specifies the JNI version used */
vm_args.options = options;
vm_args.nOptions = nbOptions;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* JNI won't complain about unrecognized options */
printf("vm_args %s\n",vm_args.options[0].optionString);
res =JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
if(res<0)<br /> {printf("JNI Error : %d\n",res);}<br /> else<br /> {printf("JNI OK");}<br /> free(classPath);<br /> free(libraryPath);<br /> //myJavaClass = (*env)->FindClass(env,"Minicom");
//constructorID = (*env)->GetMethodID(env,myJavaClass,"<init>", "()V");
//javaGUI = (*env)->NewObject(env,myJavaClass,constructorID);
for(j=0;j<itests; j++)>
for(k=0;k<ievents; k++)>
Here's the command i use to run it:
gcc -L/home/frankie/Java/JNI/Ex3 -ljava -L/home/frankie/Java/JNI/Ex3 -ljvm
-L/home/frankie/Java/JNI/Ex3 -lhpi invoke.c
Can anybody tell what i'm doing wrong??Any help will be appreciated.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Cannot start JVM - problem with JNI. Help!!