从检测方法调用自己的类时,Java NoClassDefFoundError [英] Java NoClassDefFoundError when calling own class from instrumented method

查看:285
本文介绍了从检测方法调用自己的类时,Java NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一套简单的Java代理,以帮助我(并希望其他人)对Java应用程序进行故障排除。我想创建的一个代理工具JComponent.getToolTipText()方法通过将鼠标光标悬停在它上面来快速识别任何GUI类。

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:

http://sfn.cvs.sourceforge.net/viewvc/sfn/core/src/main /java/org/leplus/sfn/transformer/JComponentTransformer.java?view=markup

我使用附件代理启动我的测试GUI,如下所示: / p>

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包含org.leplus.sfn.transformer.JComponentTransformer类。
sfn-0.1-test.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)
...

令人惊讶的是我是如果我改变我的变压器来从JRE调用任何类,它是有效的。但是当我调用自己的类org.leplus.sfn.tracer.ComponentTracer时它不起作用。我的第一个猜测是类路径问题,但ComponentTracer既在类路径中,也在代理程序的jar中。所以我迷路了。

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.

干杯,

Tom

推荐答案

这是一个类加载器问题。您正在检测由引导类加载器管理的类(javax.swing.JComponent),并让它引用由系统类加载器管理的类(org.leplus.sfn.tracer.ComponentTracer)。

It's a class loader issue. You're instrumenting a class (javax.swing.JComponent) managed by the bootstrap class loader, and having it refer to a class (org.leplus.sfn.tracer.ComponentTracer) managed by the system class loader.

如果你将ComponentTracer类放在bootstrap类加载器中,问题就会消失。

If you put your ComponentTracer class in the bootstrap class loader, the problem should disappear.

java -Xbootclasspath/p:<path/to/jar/containing/ComponentTracer> -javaagent:...

这篇关于从检测方法调用自己的类时,Java NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆