1

I made an executable jar file with manifest and everything and when I ran it in the command prompt a while ago, it worked perfectly, but now, I do the same thing, I also recreated the jar a few times, it keeps giving me this error:

Exception in thread "main" java.lang.NoClassDefFoundError: ComputingAverage (wro
ng name: me/kevinossia/mystuff/ComputingAverage)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

I am using the java -jar ComputingAverage.jar command. Why do I get this error?

gd1
  • 11,300
  • 7
  • 49
  • 88
Kevin Ossia
  • 179
  • 1
  • 3
  • 9
  • 1
    Can you show us the manifest file? – gd1 Feb 15 '13 at 20:30
  • I hope you checked this - http://stackoverflow.com/questions/6334148/exception-in-thread-main-java-lang-noclassdeffounderror – Vikram Feb 15 '13 at 20:32
  • And you might also list the contents of the jar file with `jar tvf ComputingAverage.jar` and compare those with the contents of the MANIFEST.MF file. – Alan Krueger Feb 15 '13 at 20:32
  • My manifest file looks like this: Main-Class: ComputingAverage – Kevin Ossia Feb 15 '13 at 20:37
  • My jar file only contains one class, and the jar tvf ComputingAverage.jar doesn't work, I tried adding "java" before it, and that also didn't work. – Kevin Ossia Feb 15 '13 at 20:39
  • execute `jar -tvf ComputingAverage.jar` and post the output so we can see the content of your jar. If the jar doesn't contain `me/kevinossia/mystuff/ComputingAverage.class`, that's the error. Probably you just packaged your jar in a wrong way. – Luigi R. Viggiano Feb 15 '13 at 20:50
  • It just says that "jar" is not recognized as an internal or external command, operable program, or batch file. – Kevin Ossia Feb 15 '13 at 22:05

3 Answers3

0

Verify your MANIFEST file. It indicates to JVM how your program will run.

For more information, check this article: http://www.mkyong.com/java/how-to-make-an-executable-jar-file/

Diogo Moreira
  • 1,082
  • 2
  • 9
  • 24
0

You need to make sure the paths match in the jar file and the package header in the java file.

hd1
  • 33,938
  • 5
  • 80
  • 91
0

you just try my way. Create jar file using eclipse.

Right click on your project->export->java->runnable jar file-> next-> select ComputingAverage in launch configuration dropdown box->select destination export-> select Extarct required libraries into generated jar->finish.

open cmd :- give the command like this "java -jar jarFileName"

Thats it. It should work.

Venkat Kondeti
  • 81
  • 1
  • 12