0
java -jar <Name of executable jar>

Results in my 1.6 jvm returning a NoClassDefFound error for 'jar'. Why isn't it recognising -jar as an option and not a class to run?

jar structure: The manifest points Main-Class at com.mycompany.EntryPoint.class, which is inside the jar. It also specifies Ant-Version too and I haven't set ANT_HOME env variable (running on windows).

exact runtime error:

Exception in thread "main" java.lang.NoClassDefFoundError: ûjar
caused by java.lang.ClassNotFoundException: ûjar
...

manifest:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: [redacted]
Main-Class: com/mycompany/EntryPoint

Edit: No idea why but I tried it once more and this time it executed the jar as expected.

user1561108
  • 2,666
  • 9
  • 44
  • 69
  • It probably does. It does not find the class _inside_ the JAR. Please, post your JAR's structure and the content of your manifest. – gkalpak May 18 '13 at 16:50
  • Please see my update. I see no mention of java trying to find the Class mentioned in the manifest. For instance, if I add in some other option instead of -jar it will look for a class named after that option instead, so it's not working with command line flags as expected. – user1561108 May 18 '13 at 17:02
  • What is the exact message of the error ? – gkalpak May 18 '13 at 17:05
  • NoClassDefFound , does it tell you which class ? – Peeyush May 18 '13 at 17:06
  • please see my update, sorry am copying from different box by hand. – user1561108 May 18 '13 at 17:12
  • Have you copied and pasted `java -jar ` from a document or other source ? Have you tried to type the command yourself ? – gkalpak May 18 '13 at 17:19
  • edit: I have no idea why, but I tried it one more time and now it executes... – user1561108 May 18 '13 at 17:20
  • Now admit it, you didn't type it yourself the first time ! – gkalpak May 18 '13 at 17:21
  • I honestly did! All manner of java -version java -classpath and java -jar. I'm not really sure what's going on :S – user1561108 May 18 '13 at 17:22
  • I liked this article which discribes a similar situation: http://juixe.com/techknow/index.php/2008/01/02/debugging-users-and-invisible-characters/ – gkalpak May 18 '13 at 17:23

3 Answers3

2

Probably the '-' character you're using for the '-jar' flag is not the standard ASCII '-' sign, but some kind of UTF-8 special character.

Remove it and replace it with the normal ASCII '-' sign.

Arnout Engelen
  • 6,709
  • 1
  • 25
  • 36
2

The error comes from a bad character in the command line. Most surely you are copying and pasteing java -jar <Name of executable jar>.

Write it manually ; )

aran
  • 10,978
  • 5
  • 39
  • 69
0

You need to check couple of things:

  1. Check whether manifest file is present in your jar META-INF directory
  2. If manifest file present, then whether it contains the details about your main class that need to be run when you call java -jar . Manifest file should look like this:

Manifest-Version: 1.0

Main-Class: name of class containing main

Make sure you have a line break after the last line of Manifest.mf.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136