calling java-class from c++ misses
Hello,
if I call a java-class from c++-code and the java-class imports a package (not java packages, but writen by myself), then the calling misses :-(
If I call this class without the imports - it works!
C++-Code:
jclass cls = env->FindClass(javaClassname.c_str());
if (cls == 0){
//error- cls is 0 if the java-class has imports
}
Java-Includes:
import mypackage.Conn;
import mypackage.Para;
I set the classpath to the .jar-files. Did I forget anything else?
Thx...
[732 byte] By [
XMAS1000a] at [2007-11-26 23:49:51]

# 2
> Hello,
> if I call a java-class from c++-code and the
> java-class imports a package (not java packages, but
> writen by myself), then the calling misses :-(
> If I call this class without the imports - it works!
> C++-Code:
> > jclass cls =
> env->FindClass(javaClassname.c_str());
>if (cls == 0) {
> /error- cls is 0 if the java-class has imports
>
>}
> code]
> Java-Includes:
> [code]
> import mypackage.Conn;
> import mypackage.Para;
>
>
> I set the classpath to the .jar-files. Did I forget
> anything else?
> Thx...
From the JNI Specification: http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/jniTOC.html
=======
FindClass
jclass FindClass(JNIEnv *env, const char *name);
This function loads a locally-defined class. It searches the directories and zip files specified by the CLASSPATH environment
variable for the class with the specified name.
LINKAGE:
Index 6 in the JNIEnv interface function table.
PARAMETERS:
env: the JNI interface pointer.
name: a fully-qualified class name (that is, a package name, delimited by ? followed by the class name).
If the name begins with 揫?(the array signature character), it returns an array class.
The string is encoded in modified UTF-8.
==============================
So, to find the Conn class, you need to use:
env->FindClass("mypackage/Conn");
# 3
Hi,
this is my code:
args.version = JNI_VERSION_1_4;
args.nOptions = 1;
options[0].optionString = "-Djava.class.path=C:/workspace";
args.options = options;
args.ignoreUnrecognized = JNI_FALSE;
if(CreateJavaVM(&jvm, (void **)&env, &args) != 0)
{
printf("Error: cannot create JVM\n");
return FALSE;
}
jclass cls = env->FindClass("javaclass");
if (cls == 0) {
jvm->DestroyJavaVM();
return FALSE;
}
Where should I load the java-packages? - like:
args.version = JNI_VERSION_1_4;
args.nOptions = 1;
options[0].optionString = "-Djava.class.path=C:/workspace";
args.options = options;
args.ignoreUnrecognized = JNI_FALSE;
if(CreateJavaVM(&jvm, (void **)&env, &args) != 0)
{
printf("Error: cannot create JVM\n");
return FALSE;
}
jclass cls = env->FindClass("mypackage/Conn");
cls = env->FindClass("mypackage/Para");
cls = env->FindClass("javaclass");
if (cls == 0) {
jvm->DestroyJavaVM();
return FALSE;
}
But this doesn't make sense...