• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot start JVM - problem with JNI. Help!!

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic