Skip to Main Content

Java HotSpot Virtual Machine

Announcement

Testing banner

JNI->FindClass, NoClassDefFoundError!

User_TASERAug 14 2021 — edited Aug 14 2021

Hi,

I encountered a problem when use jni_env->FindClass(...) to lookup my own class, below is my situation:
Recently I want to intercept all exception event for the web project in tomcat, so I write an exception handler (com.me.JVMTIExceptionHandler) and a shared library (libExceptCatch.so, call the exception handle method in JVMTIExceptionHandler class), in jsp write a clause to generate an NullException (index.jsp).
When start tomcat, add the jvm parameters -agentpath:/home/XXX/libExceptCatch.so, setup the CLASSPATH.
After everything is ok, and when I visit the jsp page, tomcat crashes because in libExceptCatch.so, can't find my com.me.JVMTIExceptionHandler.
I looked up the JNI Reference, say:
'Since JDK 1.2, when FindClass is called through the Invocation Interface, there is no current native method or its associated class loader. In that case, the result of ClassLoader.getSystemClassLoader is used. This is the class loader the virtual machine creates for applications, and is able to locate classes listed in the java.class.path property.'
I've also tried to set -Djava.class.path=..., still not work. Below screenshot is my configuration and codes.
Classpath.PNGjvm configuration.PNG
Error.PNG
JVMTIExceptionHandler.PNGJVMTITest.so.PNGindex.jsp.PNG
Then I write an independent class with main method not placed in tomcat, just start it using java command, it works well. I just learnt JVMTI and JNI recently, completely have no idea about this.
mainclass.PNGmain.PNGsuccess.PNGIn callbackEventException, I add a class name filter because when jvm, there're lots of exception happening, such as fail to load some jars and also can't find my class for the 2nd situation.
load.PNG
Regards,

Comments
Post Details
Added on Aug 14 2021
0 comments
166 views