Forum Stats

  • 3,825,248 Users
  • 2,260,487 Discussions


JNI->FindClass, NoClassDefFoundError!

User_TASER Member Posts: 1 Green Ribbon
edited Aug 14, 2021 9:07AM in Java Native Interface (JNI)


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 ( and a shared library (, 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/, setup the CLASSPATH.

After everything is ok, and when I visit the jsp page, tomcat crashes because in, can't find my

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.

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.

In 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.