FindClass(className) is not able to locate java class name
I am trying to invoke a java application from VC++ tool. ( Using JDK 1.3.1_18) .
It is failing to get the find the java class. FindClass is failing here.
but with JDK 1.3.1_02 , I am able to launch it.
BOOL PINJavaAppLauncher::Launch(PINJavaAppLauncher* pAppLauncher, LPSTR className, LPSTR* argList, UINT numArgs)
{
PIN_ASSERT( pAppLauncher->IsJavaVMCreated() );
VMDATA *vmd = (VMDATA*) pAppLauncher->m_hJavaVM;
if( vmd == NULL || vmd->pEnv == NULL )
{
return 0;
}
JNIEnv *pTEnv = NULL;
JDK1_1AttachArgs aargs;
int atret = vmd->pJVM->AttachCurrentThread((void**) &pTEnv, &aargs );
if( atret != 0 || pTEnv == NULL )
{
if( atret == 0 )
{
atret = 1;
}
pTEnv = vmd->pEnv;
}
jclass strClass = pTEnv->FindClass("java/lang/String");
jobjectArray args = pTEnv->NewObjectArray( numArgs, strClass, NULL );
for( UINT i = 0; i < numArgs; i++ )
{
jobject arg = (argList == NULL) ? NULL : pTEnv->NewStringUTF( argList );
pTEnv->SetObjectArrayElement(args, i, arg);
}
jclass runClass = pTEnv->FindClass(className);
BOOL fnret = TRUE;
if( runClass != NULL )
{
jmethodID mainID = pTEnv->GetStaticMethodID(runClass, "main", "([Ljava/lang/String;)V");
CString cErrMsg;
pTEnv->CallStaticVoidMethod(runClass, mainID, args);
if( pTEnv->ExceptionOccurred() )
{
pTEnv->ExceptionDescribe();
pTEnv->ExceptionClear();
not equal to null method");
fnret = FALSE;
}
}
else
{
AfxMessageBox("run class is null");
fnret = FALSE;
}
if( atret == 0 )
{
vmd->pJVM->DetachCurrentThread();
}
return fnret;
}
# 1
Hi , Can any one help me to resolve this problem?
# 2
I Got one work around by setting the java class path in the java virtual machine arguments (-DJava.class.path=C:........). but i dont think it as a solution. Bcs earlier versions of the JDK will find the class with out this arguments.
I tested upto JDK 1.3.1_15. With out this fix my program is working fine
# 3
> I tested upto JDK 1.3.1_15.
Huh?
What did you test besides that? 1.3.X has been end of lifed for several years.
And there is no way that your code found a class without having a class path set and that goes back to at least 1.1.4.
So the first step would be to determine how exactly you set the class path in the previous versions. You can start by looking at the env var CLASSPATH.
# 4
If you insist on using 1.3 you might want to start investigating immediately if any of the several daylight savings time changes that have taken place last year and this year are going to impact you (because I doubt 1.3 supports those correctly.)
# 5
>Huh?
>What did you test besides that? 1.3.X has been end of lifed for several >years.
>And there is no way that your code found a class without having a >class path set and that goes back to at least 1.1.4.
If you think so , you are living in the world of fools. Still so many old java products are supporting JDK 1.3 and still it is alive.
For DST, 1.3.1_18 will support.
I know how to set the class path for java application.
char *str2="-Djava.class.path=";
char *str3;
str3 = (char *)malloc((strlen(str2) + strlen(pszClassPath))
*sizeof(char));
strcpy(str3, str2);
strcat(str3, pszClassPath);
options[0].optionString = str3;
Then set the options to Java virtual machene. here pszClassPath means the class path of our all JAR files.
Upto JDK 1.3.1_15 , The code will find the main class with out adding ="-Djava.class.path="; infront of the Java class path.
My question is , Then why it is not supporting from JDK 1.3.1_16?
Out latest products releases are built on JDK 1.5 so this problem will come every where after JDK 1.3.1_15
Thanks,
Sibin.
# 6
> >Huh?
>
> >What did you test besides that? 1.3.X has been end
> of lifed for several >years.
>
> >And there is no way that your code found a class
> without having a >class path set and that goes back
> to at least 1.1.4.
>
> If you think so , you are living in the world of
> fools. Still so many old java products are supporting
> JDK 1.3 and still it is alive.
Presumably you are referring to the EOL comment....
As I said Sun end of life'd that version years ago.
http://java.sun.com/products/archive/eol.policy.html
http://java.sun.com/products/archive/
The second link supports exactly what I said 1.3.x is end of life'd and is no longer supported.
And unless you are willing to pay Sun a lot of money (either directly or via a lot of other sales) then they are not going to fix that version.
So even if it is a bug you are out of luck. And as I mentioned that version will not correctly deal with DST changes. So hopefully you have already dealt with that in some manner.
>
> Out latest products releases are built on JDK 1.5 so
> this problem will come every where after JDK
> 1.3.1_15
Rather confusing.
So you tested this code with 1.5 and it has this exact problem? Then why not state that?
# 7
So you are telling that , if any issues in the JDK1.3.1_18(DST patch recent one) , they will not fix it.
But there are many customers using old releases of our products which was built on JDK1.3 and they want this DST patch.
In this case , according to you we should migrate to higher version of JRE. but it is not that much easy in case of big products. It will defenitly cause some regression.
But i raised a bug in sun about this problem(I reported 1.4.2_11) through my company.
Will see what happens?
# 8
> So you are telling that , if any issues in the
> JDK1.3.1_18(DST patch recent one) , they will not fix
> it.
>
> But there are many customers using old releases of
> our products which was built on JDK1.3 and they want
> this DST patch.
And if they give Sun money, either individually or as a group, then Sun will fix it.
>
> In this case , according to you we should migrate to
> higher version of JRE. but it is not that much easy
> in case of big products. It will defenitly cause some
> regression.
>
Of course it will.
# 9
Can any one say what is the significance of -Djava.class.path= . and when they introduced it and why they introduced it.ThanksSibin.
# 10
Hi,this is the path to the java-.class files.-Djava.class.path= . means, the classes are in the workingdirectory.-Djava.class.path=D:\\workspace\\java means, the java-.class files are in the directory "D:\workspace\java"