File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The .jar classic: Exception in thread "main" java.lang.NoClassDefFoundError

 
Zachary Anderson
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difficulty being, it's not in any of the traditional places.

The first line of game.java is "package mycompany;"
I have created a jar containing all the classes of mycompany in "Game.version.jar".
The jar's manifest includes the line "Main-Class: mycompany.game", and is followed by two blank lines.
The jar includes game.class.

And yet,
java -jar Game.version.jar
causes
Exception in thread "main" java.lang.NoClassDefFoundError: mycompany/game
Caused by:
... ClassNotFoundException and various Loaders.
Could not find the main class: mycompany.game. Program will exit.

What am I missing? I'm not sure whether it's an improperly-constructed .jar, a naming problem, a classpath problem, or something completely different.
I'll keep reading up on executable .jars, but if you have a thought in the meantime I'd love to read it.
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zachary Anderson wrote:The jar includes game.class.

And is it in a subdirectory called mycompany ? And is mycompany in the root of the jar file (i.e. no more directories above it) ?
 
Ralph Cook
Ranch Hand
Posts: 479
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be aware, too, that case is significant in class names. You appear to be all right -- you say the class is game, and the error message is looking for game; I mention it partially because class names are traditionally camel-cased, and so this class would normally be spelled "Game". If it were, then the manifest would have to have the G in upper case as well.

As long as you're consistent across the board, this should still work, though you will find that other java libraries/packages/programmers will mostly use camel-case for classes.

rc
 
Zachary Anderson
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blast! J. Neal identified it correctly, I forgot about directory structure. I now have an executable .jar.
Thank you!

... now to hunt down the other bugs floating around...
 
Campbell Ritchie
Sheriff
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne knows what she is doing. It might have been better to thank her . . .
 
Ralph Cook
Ranch Hand
Posts: 479
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Joanne knows what she is doing. It might have been better to thank her . . .


Um - he/she DID thank her -- J Neal -- Joanne Neal

rc
 
Campbell Ritchie
Sheriff
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, he did. But I think the banging head rather spoiled it.

Let's leave that to lie.
 
Zachary Anderson
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, excuse me all to pieces; the headbanging was meant to indicate frustration at my own ignorance. I really am grateful for Ms. Neal's brains!
 
Campbell Ritchie
Sheriff
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies accepted
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic