Java NoClassDefFoundError when calling own class from instrumented method
Posted
by
lethal_possum
on Stack Overflow
See other posts from Stack Overflow
or by lethal_possum
Published on 2011-01-01T21:02:44Z
Indexed on
2011/01/02
1:53 UTC
Read the original article
Hit count: 584
Hello,
I am working on a kit of simple Java agents to help me (and hopefully others) troubleshoot Java applications. One of the agents I would like to create instruments the JComponent.getToolTipText() method to quickly identify any GUI class by just hovering the mouse cursor over it.
You can find the code of my transformer and the rest of the project here:
I launch my test GUI with the agent attached as follow:
$ java -javaagent:target/jars/sfn-0.1-agent.jar=JComponent -cp lib/jars/bcel-5.2.jar:target/jars/sfn-0.1-test.jar:target/jars/sfn-0.1-agent.jar org.leplus.sfn.test.Main
sfn-0.1-agent.jar contains the org.leplus.sfn.transformer.JComponentTransformer class. sfn-0.1-test.jar contains the org.leplus.sfn.test.Main class.
Here is what the application prints when I launch it and I put the mouse over it:
Loading agent: JComponent Instrumentation ready! Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/leplus/sfn/tracer/ComponentTracer at javax.swing.JComponent.getToolTipText(JComponent.java) at javax.swing.ToolTipManager$insideTimerAction.actionPerformed(ToolTipManager.java:662) ...
What is surprising to me is that if I change my transformer to call any class from the JRE, it works. But it doesn't work when I call my own class org.leplus.sfn.tracer.ComponentTracer. My first guess was a classpath issue but the ComponentTracer is both in the classpath and in the agent's jar. So I am lost.
If any of you see where I am missing something.
Cheers,
Tom
© Stack Overflow or respective owner