English 中文(简体)
奇数NoClassDefFoundError
原标题:Odd 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;
...

所以用相同的类路径运行<code>javap</code>可以找到类,但<code>java</code〕单独运行不行。WTF正在进行吗?

我检查了这两个程序是否来自同一个安装Java(/usr/lib64/jvm/Java-1.6.0-sun),即Java 6和类是为Java 5编译的。清单未签名。JAR文件是可读的(<code>unzip-t</code>报告没有错误)。

最佳回答

一个词:应用装甲

在我的案例中,配置不允许程序java从新的安装路径加载JAR。

如果您有类似的问题,请查看/var/log/audit.log。您应该会在那里看到错误消息。

问题回答

NoClassDefFoundError在找到类本身但类加载器无法加载所需的所有类时发生。

是否可以检查类<code>org.gudy.azureus2.ui.swt.Main.java</code>的导入头,并确保所有导入的类都可以在类路径中找到。如果没有,请将jar文件添加到类路径中。

如果你想让我帮忙找出仍然需要的东西,请张贴导入部分。

您的异常是java.lang.NoClassDefFoundError,而不是ClassNotFoundException-因此javap仍然能够反汇编类。

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 execute org.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.

同样,运行SWT有时需要将<code>-Djava.library.path</code>设置为<code>SWT</code<库(看看你的SO声誉,我想你知道这一点)

Edit Here is a link to one Azureus shell script, which lists more classpath JARs.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签