sgold
asked on
jni jdk1.2.2 classpath and env->FindClass
Hi all
I am writing a cpp app using vc++6 on nt that calls java metode
using jni
the code is:
#include "stdafx.h"
#include <jni.h>
#include <string.h>
#include <windows.h>
JNIEnv *env;
JavaVM *jvm;
jmethodID mid;
jint ret;
jclass clazz;
JDK1_1InitArgs vm_args;
HANDLE hLib = NULL;
typedef jint (*P_JNI_GetDefaultJavaVMIn itArgs)(vo id *args);
int main(int argc, char* argv[])
{
//char* classpath;
char szClassPath [14];
vm_args.version =JNI_VERSION_1_2; //0x00010002;
if(JNI_GetDefaultJavaVMIni tArgs (&vm_args))
{
fprintf(stderr,"version not soported");
return 1;
}
// Tell the JVM where to find the application class files
wsprintf (szClassPath,"c:\\jdk1.2.2 \\jre\\lib \\rt.jar;D :\\JavaCla sses");
vm_args.classpath = szClassPath;
// Attempt to create a JVM instance.
if ((ret = JNI_CreateJavaVM (&jvm, (void**)&env, &vm_args)) < 0)
{
fprintf (stderr, "Can't create JVM. Error: %ld\n", ret);
return 1;
}
if ((clazz = env->FindClass ("HelloWorld")) == 0) //this metoden is faild
{
fprintf (stderr, "Can't locate the HelloWorld class. Exiting...\n");
return 1;
}
// Attempt to locate the class main method.
if ((mid = env->GetStaticMethodID (clazz, "main", "([Ljava/lang/String;)V")) == 0)
{
fprintf (stderr, "Can't locate the main method. Exiting...\n");
return 1;
}
// Launch main method.
env->CallStaticVoidMethod (clazz, mid);
// Destroy the JVM instance.
jvm->DestroyJavaVM ();
return 0;
}
But I get the cant find class HelloWorld error (added remark above to show metode that field)
I think its somthing whith the classpath
in the documentation and samples they set the classpath to
classes.zip but in jdk1.2.2 this class was replaced with rt.jar I tried to set path to it (as shown above) but it didnt solved the prob(I tried all so whith no path to it and path "." allso no result)
well if someon can tell me what I am doing rong
(please no examp in jdk1.1.. and c class there planty of them on the web but cpp and jdk1.2.2 are in lack even in sun specs and site)
tanx
I am writing a cpp app using vc++6 on nt that calls java metode
using jni
the code is:
#include "stdafx.h"
#include <jni.h>
#include <string.h>
#include <windows.h>
JNIEnv *env;
JavaVM *jvm;
jmethodID mid;
jint ret;
jclass clazz;
JDK1_1InitArgs vm_args;
HANDLE hLib = NULL;
typedef jint (*P_JNI_GetDefaultJavaVMIn
int main(int argc, char* argv[])
{
//char* classpath;
char szClassPath [14];
vm_args.version =JNI_VERSION_1_2; //0x00010002;
if(JNI_GetDefaultJavaVMIni
{
fprintf(stderr,"version not soported");
return 1;
}
// Tell the JVM where to find the application class files
wsprintf (szClassPath,"c:\\jdk1.2.2
vm_args.classpath = szClassPath;
// Attempt to create a JVM instance.
if ((ret = JNI_CreateJavaVM (&jvm, (void**)&env, &vm_args)) < 0)
{
fprintf (stderr, "Can't create JVM. Error: %ld\n", ret);
return 1;
}
if ((clazz = env->FindClass ("HelloWorld")) == 0) //this metoden is faild
{
fprintf (stderr, "Can't locate the HelloWorld class. Exiting...\n");
return 1;
}
// Attempt to locate the class main method.
if ((mid = env->GetStaticMethodID (clazz, "main", "([Ljava/lang/String;)V"))
{
fprintf (stderr, "Can't locate the main method. Exiting...\n");
return 1;
}
// Launch main method.
env->CallStaticVoidMethod (clazz, mid);
// Destroy the JVM instance.
jvm->DestroyJavaVM ();
return 0;
}
But I get the cant find class HelloWorld error (added remark above to show metode that field)
I think its somthing whith the classpath
in the documentation and samples they set the classpath to
classes.zip but in jdk1.2.2 this class was replaced with rt.jar I tried to set path to it (as shown above) but it didnt solved the prob(I tried all so whith no path to it and path "." allso no result)
well if someon can tell me what I am doing rong
(please no examp in jdk1.1.. and c class there planty of them on the web but cpp and jdk1.2.2 are in lack even in sun specs and site)
tanx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER