FindClass() returning 0
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aaron_Scifres
Posted On:   Friday, July 11, 2003 06:30 AM

Hello, I am using the Invocation API to make calls into a Java class from a C++ application. I have a working simple example of calling a Java class from a DLL, but when I have tried to incorporate it into my larger program, it fails to find the Java class. I have tried both adding the .jar file in which the class resides to the classpath, and simply placing the .class file in a directory and adding that directory to the classpath (via the -Djava.class.path option), yet neither seems to work. Any ideas as to what I am doing wrong? A simplified version of my code is below: SingletonJVM::SingletonJVM() { m_javaName = "com/mycompany/pathtoclass/JNIClass"; // the name of our class    More>>

Hello,


I am using the Invocation API to make calls into a Java class from a C++ application. I have a working simple example of calling a Java class from a DLL, but when I have tried to incorporate it into my larger program, it fails to find the Java class. I have tried both adding the .jar file in which the class resides to the classpath, and simply placing the .class file in a directory and adding that directory to the classpath (via the -Djava.class.path option), yet neither seems to work. Any ideas as to what I am doing wrong? A simplified version of my code is below:


			
SingletonJVM::SingletonJVM()
{
m_javaName = "com/mycompany/pathtoclass/JNIClass"; // the name of our class

// create JVM
char *cpath = getenv("CLASSPATH");
std::basic_string classPath = getLoadDirectory(); // the jar lives with the loaded dll
classPath += "\JNIClass.jar;";
classPath += cpath;
jint res;
JavaVMInitArgs vm_args;
JavaVMOption options[1];
char newcpath[512];
sprintf(newcpath, "-Djava.class.path=".;%s"", classPath.c_str());
options[0].optionString = newcpath;
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;

/* Create the Java VM */
res = JNI_CreateJavaVM(&m_jvm, (void**)&m_env, &vm_args);
if (res == JNI_EEXIST)
{
JavaVM *jvms[1];
jsize nVMs;
res = JNI_GetCreatedJavaVMs(jvms, 1, &nVMs);
m_jvm = jvms[0];
m_jvm->AttachCurrentThread((void**)&m_env, NULL);
}
else if (res < 0)
{
m_jvm = NULL;
}
}

char *SingletonJVM::doJNI(int &code)
{
// tests to make sure JVM and environment exist go here
jclass cls;
jmethodID mid;
jthrowable except = NULL;
cls = m_env->FindClass(m_javaName);
if (cls == 0)
{
checkException(ex);
code = JNI_MISSING_CLASS;
return m_javaName;
}
...
}


Thanks for any help you can provide.


-Aaron

   <<Less

Re: FindClass() returning 0

Posted By:   Julie_Szmyd  
Posted On:   Friday, July 11, 2003 10:17 AM

Try using a ':' instead of a ';' in your classpath:


sprintf(newcpath, "-Djava.class.path=".:%s"", classPath.c_str());
About | Sitemap | Contact