0
votes

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.findClass(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!

6

6 Answers

2
votes

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

1
votes

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.

0
votes

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.

0
votes

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.

0
votes

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.

0
votes

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