Search code examples
javainstrumentationjavassist

Javassist java.lang.NoClassDefFoundError


I want to instrument a library method to call one of my Class present in javassist agent.

Lets say I have a class:

Class A {

    void display() {
        System.out.println("Inside A.dipslay()");
    }
}

then when I invoke:

method.insertAfter("packageName.A.display()");

it throws the exception:

Exception in thread "main" java.lang.NoClassDefFoundError: packageName/A
    at java.net.HttpURLConnection.setRequestMethod(libraryClass)
    at sun.net.www.protocol.http.HttpURLConnection.setRequestMethod(libraryClass)
    at com.avekshaa.app.SecurityFilter.sendGet(Class where i call the Library Class)
    at com.avekshaa.app.SecurityFilter.main(Class where i call the Library Class)

And when I call it just by name:

method.insertAfter("A.display()");

then it gives a No such class found Exception.


Solution

  • I solved the issue by adding the jars path in the javassist manifest file. Reffer - this