开发者

NoClassDefFoundError points to the wrong class

开发者 https://www.devze.com 2022-12-29 06:54 出处:网络
I\'m validating the installation of a program that consists of a few separate modules. They are not co-dependent. I have apple.jar and orange.jar, they are placed in the same folder and were developed

I'm validating the installation of a program that consists of a few separate modules. They are not co-dependent. I have apple.jar and orange.jar, they are placed in the same folder and were developed in the same project, but run independent of each other.

Running apple.jar goes fine, but orange.jar gives me a NoClassDefFoundError pointing to apple.jar.

/usr/java/jre1.6.0_14/bin/java -jar validator.jar

Exception in thread "main" java.lang.NoClassDefFoundError: orange/client/Apple Caused by: java.lang.ClassNotFoundException: orange.client.Apple at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.fi开发者_JAVA技巧ndClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) Could not find the main class: validator/client/StormDataXMLGenerator. Program will exit.

The manifest file lists Orange as the correct main class.

Main-Class: orange/client/Orange

Anybody know why it's giving me the NoClassDefFoundError? Thanks in advance!


Perhaps orange.client.Orange depends upon orange.client.Apple? It looks like your main class has already been loaded, so I would guess some other class is trying to bring in orange.client.Apple.

Or maybe java's missing a banana :-)


I'm not sure if this is the cause of your problem, but where you say you have

Main-Class: orange/client/Orange

I think it should be

Main-Class: orange.client.Orange

At least this is how all the examples I have seen do it.


It looks like despite your best efforts, some inter-dependencies have crept in between the code in orange.jar and apple.jar. If you have access to the source code, take a look at the import statements for all classes in orange.jar, to see if they reference anything in apple.jar.


Java has the concept of a classpath. You have to add apple.jar to the classpath, so orange.jar can find the apples.

Call your app like this:

java -cp apple.jar -jar orange.jar

Alternatively you can set the CLASSPATH environment variable.


The "Main-Class" property in validator.jar's manifest must be set to "orange.client.Apple". So that class must not be part of your JAR. Two things you can try: Add that class to your JAR file, or add that class to your classpath.


Thanks for all the responses! There was apparently a problem with the build.xml used to create the jars. It's been fixed now :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号