aspose file tools*
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
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
Author

Cannot start JVM - problem with JNI. Help!!

frankie aranha
Greenhorn

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>
#include<stdio.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);

strcpy(classPath,
"/home/frankie/Java/JNI/Ex3:/home/frankie/jdk1.2.2/jre/lib/i386:
/home/frankie/Java/JNI/Ex3:/usr/include:/home/frankie/jdk1.2.2/include");
libraryPath = malloc(500);
strcpy(libraryPath, "/home/frankie/Java/JNI/Ex3");
nbOptions=0;
options[0].optionString=classPath;
nbOptions++;
options[1].optionString=libraryPath;
nbOptions++;
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);
printf("testing...\n");
itests=5;
count=0;
outcount=0;
ievents=10;
for(j=0;j<itests; j++)>
{
printf("Test:%d\n",++outcount);
count=0;
for(k=0;k<ievents; k++)>
{
count++;
printf("Check");
sleep(1);
}
}
}
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.
..Frankie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot start JVM - problem with JNI. Help!!
 
Similar Threads
JNI - FindClass
Linking JNI code to JVM.dll file.......Getting Error
invoking jvm on windows plat. through c
JNI_CreateJavaVM returns with -1
Have anyone try this code?