奇怪的 NoClassDefFoundError
安装最新版本的 Vuze (Azureus) 后,我在尝试启动它时遇到了一个奇怪的错误:
> java -Xmx128m -classpath ./Azureus2.jar:./swt.jar -Djava.library.path=/bt_work/vuze -Dazureus.install.path=/bt_work/vuze -Dazureus.script=./azureus -Dazureus.script.version=2 org.gudy.azureus2.ui.swt.Main
Exception in thread "main" java.lang.NoClassDefFoundError: org/gudy/azureus2/ui/swt/Main
Caused by: java.lang.ClassNotFoundException: org.gudy.azureus2.ui.swt.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
奇怪的是:
> javap -classpath ./Azureus2.jar:./swt.jar org.gudy.azureus2.ui.swt.Main
Compiled from "Main.java"
public class org.gudy.azureus2.ui.swt.Main extends java.lang.Object{
public static final java.lang.String PR_MULTI_INSTANCE;
...
所以...使用相同的类路径运行 javap
会找到该类,但 单独使用 java 是不行的。这是怎么回事?
我检查了这两个程序都来自同一个安装 Java (/usr/lib64/jvm/java-1.6.0-sun
),即 Java 6,并且这些类是为 Java 5 编译的。清单是没签。 JAR 文件是可读的(unzip -t
报告没有错误)。
After installing the latest version of Vuze (Azureus), I got an odd error trying to start it:
> java -Xmx128m -classpath ./Azureus2.jar:./swt.jar -Djava.library.path=/bt_work/vuze -Dazureus.install.path=/bt_work/vuze -Dazureus.script=./azureus -Dazureus.script.version=2 org.gudy.azureus2.ui.swt.Main
Exception in thread "main" java.lang.NoClassDefFoundError: org/gudy/azureus2/ui/swt/Main
Caused by: java.lang.ClassNotFoundException: org.gudy.azureus2.ui.swt.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
What's odd is this:
> javap -classpath ./Azureus2.jar:./swt.jar org.gudy.azureus2.ui.swt.Main
Compiled from "Main.java"
public class org.gudy.azureus2.ui.swt.Main extends java.lang.Object{
public static final java.lang.String PR_MULTI_INSTANCE;
...
So ... running javap
with the same classpath finds the class but java
alone can't. WTF is going on?
I checked that both programs come from the same install Java (/usr/lib64/jvm/java-1.6.0-sun
), that's Java 6 and the classes were compiled for Java 5. The manifest isn't signed. The JAR file is readable (unzip -t
reports no errors).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当找到类本身但类加载器无法加载它需要的所有类时,会发生
NoClassDefFoundError
。您能否检查类
org.gudy.azureus2.ui.swt.Main.java
的导入标头,并确保可以在类路径中找到所有导入的类。如果没有,请将 jar 文件添加到类路径中。如果您希望我帮助找出还需要什么,请发布导入部分。
NoClassDefFoundError
happens when the class itself is found but the class loader cannot load all the classes it needs.Can you check the import headers for class
org.gudy.azureus2.ui.swt.Main.java
and make sure that all the imported classes can be found in your classpath. If not, add the jar files to your classpath.Post the import section if you want me to help figure out what is still needed.
一个词: AppArmor
在我的例子中,配置不允许程序
java< /code> 从新的安装路径加载 JAR。
如果您遇到类似问题,请查看
/var/log/audit.log
。您应该在那里看到错误消息。One word: AppArmor
In my case, the config didn't allow the program
java
to load the JARs from the new installation path.If you have a similar problem, look into
/var/log/audit.log
. You should see the error messages there.您的异常是
java.lang.NoClassDefFoundError
,而不完全是ClassNotFoundException
- 因此javap
仍然能够反汇编该类。您可能知道
NoClassDefFoundError
可以被视为链接错误。我倾向于猜测运行时缺少一些执行 org.gudy.azureus2.ui.swt.Main 所需的类我想它在类路径上需要更多的 JAR。
因此 org.gudy.azureus2.ui.swt.Main 可用(这就是 javap 工作的原因),但在运行时找不到其依赖项之一。
另外,运行 SWT 有时需要将
-Djava.library.path
设置为swt
库(看看你的 SO 声誉,我猜你知道这一点)编辑
以下是一个 Azureus shell 脚本的链接,其中列出了更多类路径 JAR。
Your exception is
java.lang.NoClassDefFoundError
and not exactlyClassNotFoundException
- sojavap
will still be able to disassemble the class.As you might know
NoClassDefFoundError
can be seen as a linkage error. I tend to guess that the runtime is missing some required class to executeorg.gudy.azureus2.ui.swt.Main
I guess it requires more JARs on classpath.
So
org.gudy.azureus2.ui.swt.Main
is available (that is why javap works) but one of its dependency is not found during runtime.Also running SWT sometimes requires
-Djava.library.path
set toswt
library (looking at your SO reputation I guess you know this)Edit
Here is a link to one Azureus shell script, which lists more classpath JARs.