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.

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.

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

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.

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

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

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

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

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

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

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?

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

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

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?

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.

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

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.

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

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

Just by you can type in a new message there's a "mark this thread solved" link - just click it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.