File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Murach's Java Servlets and JSP this week in the Servlets 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.
I agree. Here's the link:
subject: Cannot start JVM - problem with JNI. Help!!
Similar Threads
invoking jvm on windows plat. through c
Have anyone try this code?
Linking JNI code to JVM.dll file.......Getting Error
JNI_CreateJavaVM returns with -1
JNI - FindClass