JNI Invokation problems on Solaris

H

Hf

Hi there

I am having a strange problem with JNI on Solaris 8 & Solaris 9 (JDK
1.4.1_02) with the recommended J2SE patch applied

My code works fine if I Create a JVM and then proceed to invoke my Java code
from the env retruned by JNI_CreateJavaVM. However as soon as I deatach the
current thread from the Vm and then re-attach using AttachCurrentThread my
Java throws an exception as shown below

Exception in thread "Thread-0" javax.xml.parsers.FactoryConfigurationError:
Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
at
javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.
java:99)


Now nothing to do with classpaths or anything else has changed so why am I
getting an error just because I used AttachCurrentThread ?

If I replace the Java code with a very basic class that does nothing but
output to the console and calls some native functions everything works fine
so maybe it is something to do with the AttachCurrentThread and JAX but I'm
at a loss.

Exactly the same code works perfectly on Windows XP.

This is actually a simplification of the final problem which will be
attaching from multiple threads to the JVM to run the Java. By calling
DetachCurrentThread followed by AttachCurrentThread I am getting the same
error without the complication of the extra threads.

My code is summarized below (i've removed error checks for clarity). Can
anyone suggest a reason why this error occurs on Solaris.

TIA
Adrian


// The Global JVM Pointer
static JavaVM *theJVM = NULL;

JavaVM* nsvr_GetPointerToTheJVM()
{
if(theJVM != NULL)
{
return theJVM;
}
else
{
JNIEnv *env = NULL;
jint res;

JavaVMInitArgs vm_args;
JavaVMOption options[2];
options[0].optionString = "-Djava.class.path=" OCTOPUS_CLASSPATH;
options[1].optionString =
"-DOCTOPUS_HOME=/export/home/buildmc/testPas_Adrian/Octopus";
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 2;
vm_args.ignoreUnrecognized = JNI_TRUE;

res = JNI_CreateJavaVM(&theJVM, (void**)&env, &vm_args);

if (res < 0)
return NULL; // Can't create Java VM

//Comment the following line out and the Java runs fine
theJVM->DetachCurrentThread();

return theJVM;
}
}

int doOctopus(char* pOctoFilename)
{
JavaVM *jvm = NULL;
JNIEnv *env = NULL;
jint res, res2;
jclass cls;
jmethodID mid, mid2, mid3, clsCons;
jstring jstr, jstr2, jstr3;
jclass stringClass;
jobjectArray args, args2, args3;
jstring jStr4;
const char *str;
jobject clsInstance;

int rc = 0;

const JNINativeMethod methods[] = {
{
"publishProgress",
"(Ljava/lang/String;)I",
&publishProgress__String
},
{
"publishProgress",
"(II)I",
&publishProgress__II
},
{
"publishProgress",
"(IIF)I",
&publishProgress__IIF
}
};


printf("In doOctopus()!\n");

jvm = nsvr_GetPointerToTheJVM();

if(jvm != NULL)
jvm->AttachCurrentThread((void **)&env, NULL);

if(jvm != NULL && env != NULL)
{
cls = (*env).FindClass("org/webdocwf/util/loader/Loader");
if (cls != 0)
{
res2 = env->RegisterNatives(cls, methods, 3); //Register Native
methods for progressFeedback

mid = (*env).GetStaticMethodID(cls, "main","([Ljava/lang/String;)V");
jstr = (*env).NewStringUTF(pOctoFilename);

stringClass = (*env).FindClass("java/lang/String");
args = (*env).NewObjectArray(1, stringClass, jstr);

(*env).CallStaticVoidMethod( cls, mid, args);
}

if ((*env).ExceptionOccurred())
{
(*env).ExceptionDescribe();
}

if (cls != 0)
res2 = env->UnregisterNatives(cls);

res = jvm->DetachCurrentThread();
}

return 0;
}

int main(int argc, char* argv[])
{
char* octoFile1 =
"/export/home/buildmc/testPas_Adrian/Octopus/sInstoreJob.xml";

printf("C++ Hello from main()!\n");

int iRes = 0;

iRes = doOctopus(octoFile1);

return iRes;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top