getting a NoClassDefFoundError

I've created a simple "Hello World"-Example with AWT, a small window pops up saying "Hello World". When bundling the application in a jar-file (I called it "ShowHelloworld.jar"), everything works fine. But when I try to run the file, I'm getting the NoClassDefFoundError:

C:\JBuilder4\jdk1.3\bin > java -jar ShowHelloworld.jar

Exception in thread"main" java.lang.NoClassDefFoundError: ShowHelloworld (wrong name: helloworld/ShowHelloworld)

at java.lang.ClassLoader.defineClass0(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:486)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)

at java.net.URLClassLoader.access$100(URLClassLoader.java:56)

at java.net.URLClassLoader$1.run(URLClassLoader.java:195)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:297)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)

at java.lang.ClassLoader.loadClass(ClassLoader.java:253)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)

This is my manifest-file:

Manifest-Version: 1.0

Main-Class: ShowHelloworld

Created-By: 1.3.0 (Sun Microsystems Inc.)

This file contains two classes: ShowHelloworld.class (which contains the main-class) and ShowHelloworld$1.class.

What have I done wrong?

[1611 byte] By [hzirl] at [2007-9-26 8:03:54]
# 1

If you had not used a package, then nothing would have gone wrong. If you were to remove your package statement, and re-built / updated your jar, it would have worked. In order to use packages however, you need to include them in the process.

Your package name is helloworld, so you need to create a directory called helloworld and copy your ShowHelloworld.class to that directory. Then, build your jar with this:

> jar cmf (manifest) (jar name) (package/classes)

> jar cmf manifest ShowHelloworld.jar helloworld/ShowHelloworld.class

But wait! Before you do that, you'll need to fix the manifest to include the package name as well.

Main-Class:helloworld/ShowHelloworld

Ok, now build the jar and run it:

> java -jar ShowHelloworld.jar

-Ron

rSully at 2007-7-1 18:24:29 > top of Java-index,Desktop,Deploying...
# 2
Thank you very much, Ron! That was it, now my program is running perfectly!Henrietta
hzirl at 2007-7-1 18:24:29 > top of Java-index,Desktop,Deploying...
# 3
Your welcome. :)I was kinda worried tho, because I forgot to include your ShowHelloworld$1.class in my instructions, so I'm glad you were able to figure it out :)-Ron
rSully at 2007-7-1 18:24:29 > top of Java-index,Desktop,Deploying...
# 4
Hi Henrietta,Would you please assign those dukes you offered to me? I'd appreciate it :)Thanks,-Ron
rSully at 2007-7-1 18:24:29 > top of Java-index,Desktop,Deploying...