1,105,644 Community Members

weird jar-file

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hey!

I got a Java Project which runs fine when i call the Main class with the java command. Made it into a -jar file with:
jar cmfv manifest kort.jar *

the manifest file contains

Main-Class: src.KortBord

with the line break at the end

when i try to:
java -jar kort.jar

i get:

Exception in thread "main" java.lang.NoClassDefFoundError: src/KortBord (wrong name: KortBord)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: src.KortBord. Program will exit.

aka. NoClassDefFoundError

I have unzipped the .jar and everything looks okay. META-INF/MANIFEST.MF contains the Main-Class and the .class files are there.

I run Ubuntu 11.10 and OpenJDK 6

the class files extends JFrame and JComponent with som ActionsListeners and MouseListeners. nothing special.

Member Avatar
stultuske
Posting Expert
5,326 posts since Jan 2007
Reputation Points: 938 [?]
Q&As Helped to Solve: 776 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

well, the api's state that a NoClassDefFoundError is:

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

so probably something is missing when you run your .jar.
'm not really sure what to look for here.

Member Avatar
JamesCherrill
... trying to help
10,383 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,752 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

Two more things to check:
is the class file in a folder called "src" in the jar?
is all the capitalisation correct (file names in a jar are case-sensitive)?

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

the last time i had them all in the src since i just compiled with java. Therefore the src.KortBord. also tried when i got them in bin.KortBord but makes no differance.

Have checked the manifest file + class names for caps, everything is good.

Member Avatar
JamesCherrill
... trying to help
10,383 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,752 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

Can you print the contents of the manifest file and the jar and post the results here?
jar tf kort.jar

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Can this possibly have anything to do with the package thingy?

Member Avatar
JamesCherrill
... trying to help
10,383 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,752 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

Can this possibly have anything to do with the package thingy?

Yes. Your class file has to be in a directory structure that exactly follows the package structure

Member Avatar
stultuske
Posting Expert
5,326 posts since Jan 2007
Reputation Points: 938 [?]
Q&As Helped to Solve: 776 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

package 'thingy'? what is a package 'thingy'?

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

in META-INF/MANIFEST.MF

Manifest-Vertsion: 1.0
Created-By: 1.6.0_23 (Sun Microsystems Inc.)
Main-Class: bin.KortBord

Kontents of jar looks like:
http://i39.tinypic.com/npl1ug.png

http://i41.tinypic.com/fdydrd.png

Member Avatar
JamesCherrill
... trying to help
10,383 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,752 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

OK, now what is the package statement at the start of the source code for KortBord?

Member Avatar
stultuske
Posting Expert
5,326 posts since Jan 2007
Reputation Points: 938 [?]
Q&As Helped to Solve: 776 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

ehm ... I thought you said the line was:
Main-Class: src.KortBord
?

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

package 'thingy'? what is a package 'thingy'?

the java package keyword.

like

package com.example;

if that could influence the jar files behavior even when it works when calling the class file with the java command?

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

ehm ... I thought you said the line was:
Main-Class: src.KortBord
?

it was. I've hammered my head against it multiple ways and now the class files is in the src folder and therefor the MainClass is set to src

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Can you print the contents of the manifest file and the jar and post the results here?
jar tf kort.jar

didn't see the last command.
well here goes:
META-INF/
META-INF/MANIFEST.MF
150/
150/.DS_Store
150/back-blue-150-1.png
150/back-blue-150-2.png
150/back-blue-150-3.png
150/back-blue-150-4.png
150/back-red-150-1.png
150/back-red-150-2.png
150/back-red-150-3.png
150/back-red-150-4.png
150/clubs-10-150.png
150/clubs-2-150.png
150/clubs-3-150.png
150/clubs-4-150.png
150/clubs-5-150.png
150/clubs-6-150.png
150/clubs-7-150.png
150/clubs-8-150.png
150/clubs-9-150.png
150/clubs-a-150.png
150/clubs-j-150.png
150/clubs-k-150.png
150/clubs-q-150.png
150/diamonds-10-150.png
150/diamonds-2-150.png
150/diamonds-3-150.png
150/diamonds-4-150.png
150/diamonds-5-150.png
150/diamonds-6-150.png
150/diamonds-7-150.png
150/diamonds-8-150.png
150/diamonds-9-150.png
150/diamonds-a-150.png
150/diamonds-j-150.png
150/diamonds-k-150.png
150/diamonds-q-150.png
150/hearts-10-150.png
150/hearts-2-150.png
150/hearts-3-150.png
150/hearts-4-150.png
150/hearts-5-150.png
150/hearts-6-150.png
150/hearts-7-150.png
150/hearts-8-150.png
150/hearts-9-150.png
150/hearts-a-150.png
150/hearts-j-150.png
150/hearts-k-150.png
150/hearts-q-150.png
150/joker-b-150.png
150/joker-r-150.png
150/spades-10-150.png
150/spades-2-150.png
150/spades-3-150.png
150/spades-4-150.png
150/spades-5-150.png
150/spades-6-150.png
150/spades-7-150.png
150/spades-8-150.png
150/spades-9-150.png
150/spades-a-150.png
150/spades-j-150.png
150/spades-k-150.png
150/spades-q-150.png
bin/
bin/Card.class
bin/CardDeck.class
bin/KortBord.class
bin/KortBord$1.class
manifest
#manifest#
manifest~
src/
src/Card.java
src/CardDeck.java
src/KortBord.java
src/KortBord.java~
src/CardDeck.java~
src/Card.java~
src/Card.class

Member Avatar
stultuske
Posting Expert
5,326 posts since Jan 2007
Reputation Points: 938 [?]
Q&As Helped to Solve: 776 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

well, first of all, in that part of Manifest code you showed, the line was:
Main-Class: bin.KortBord
you have to link to your class, not to your .java file.
what does the package statement in your .java file say?

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

well, first of all, in that part of Manifest code you showed, the line was:
Main-Class: bin.KortBord
you have to link to your class, not to your .java file.
what does the package statement in your .java file say?

As you can see on the printout over the .class files are in the bin folder. This should not be a problem. It didn't work when i had src.KortBord and kept all the .class files in the src folder either.

the package statement say nothing. Can that be a problem? In that case what should it say when the files are directly put in the src and bin folders.

Member Avatar
stultuske
Posting Expert
5,326 posts since Jan 2007
Reputation Points: 938 [?]
Q&As Helped to Solve: 776 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

so, you manually place your classes in the bin folder?
if you do, I assume that's your problem.

Member Avatar
JamesCherrill
... trying to help
10,383 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,752 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

Your class directory structure must exactly match your package structure. If you have no package spec then you should not have any directories for the class files, they should just be "loose" in the jar.

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Problem solved.... Thank you very much for all the help

Member Avatar
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

LOL. One last newb question. How do i mark the thread as solved?

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: