Odd NoClassDefFoundError

807 views Asked by At

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).

3

There are 3 answers

0
Aaron Digulla On BEST ANSWER

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.

0
gigadot On

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.

0
ring bearer On

Your exception is java.lang.NoClassDefFoundError and not exactly ClassNotFoundException - so javap 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 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.

Also running SWT sometimes requires -Djava.library.path set to swt 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.