| Author |
The .jar classic: Exception in thread "main" java.lang.NoClassDefFoundError
|
Zachary Anderson
Ranch Hand
Joined: Oct 14, 2005
Posts: 49
|
|
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
Joined: Aug 05, 2005
Posts: 3011
|
|
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) ?
|
Joanne
|
 |
Ralph Cook
Ranch Hand
Joined: May 29, 2005
Posts: 479
|
|
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
Joined: Oct 14, 2005
Posts: 49
|
|
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
Joined: Oct 13, 2005
Posts: 32704
|
|
|
Joanne knows what she is doing. It might have been better to thank her . . .
|
 |
Ralph Cook
Ranch Hand
Joined: May 29, 2005
Posts: 479
|
|
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
Joined: Oct 13, 2005
Posts: 32704
|
|
Yes, he did. But I think the banging head rather spoiled it.
Let's leave that to lie.
|
 |
Zachary Anderson
Ranch Hand
Joined: Oct 14, 2005
Posts: 49
|
|
|
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
Joined: Oct 13, 2005
Posts: 32704
|
|
Apologies accepted
|
 |
 |
|
|
subject: The .jar classic: Exception in thread "main" java.lang.NoClassDefFoundError
|
|
|