We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,619 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

weird jar-file

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.

3
Contributors
20
Replies
2 Hours
Discussion Span
1 Year Ago
Last Updated
21
Views
Question
Answered
Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23

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)?

JamesCherrill
... trying to help
Moderator
8,496 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29

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.

Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

JamesCherrill
... trying to help
Moderator
8,496 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29

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

Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

JamesCherrill
... trying to help
Moderator
8,496 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29

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

stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23

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

Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

JamesCherrill
... trying to help
Moderator
8,496 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29

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

stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23

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?

Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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?

stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23

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.

Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23

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.

JamesCherrill
... trying to help
Moderator
8,496 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29

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

Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Kjeks
Newbie Poster
10 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1194 seconds using 2.71MB