Search code examples
javamavenclassloaderclassnotfoundexceptioninstrumentation

Java Instrumentation for URI class: Adding a dependency throws ClassNotFoundException


I have instrumented an URI Constructor to write the created URI to a logshipper. The Logshipper class is part of my Agent Library which is both a maven dependency and a runtime Arg.

The Instrumentation inside the Agent uses a ClassFileTransformer to add the line of code to that constructor. However, when the constructor is called, it throws a ClassNotFoundException with detailMessage: edu/overbeck/masterarbeit/agent/LogShipper. When I take a look in the ClassLoader, the Class is however loaded. A screenshot of my IntelliJ debugger: ![Weird err][1]

Why does this happen? My other instrumented class, ContentLengthOutputStream from the Apache HTTP-core library, works fine with the LogShipper. [1]: https://i.sstatic.net/vf8b4.png


Solution

  • It was a class loader issue - answered and explained well here: Java NoClassDefFoundError when calling own class from instrumented method Adding my AgentLib containing the LogShipper class as XBootclasspath helped.