Jesse Brands Jesse Brands - 1 year ago 48
Java Question

Creating a .JAR file fails

I'm using Eclipse, and I have a pretty simple project, I'll save you the code. It executes just fine and runs just fine. It has two .java files, in fact, the project tree is like this:

- src/ (dir)
mewlog/ (package)
- (surprise, this one contains main and some initialization methods)
mlGUI/ (package)
- this one is empty (empty package!)

So, I go to File -> Export. I follow the steps as per usual and it makes my .JAR file just fine without any warnings or issues. Good!

So far so good one would say, so I rush up to my Terminal, navigate to the folder I exported my jar in, and execute it as follows:

java -jar mewLog_macosx-x86.jar

BAM! Here it goes wrong, the terminal gives me the following output:

Exception in thread "main" java.lang.NoClassDefFoundError: MLMain
Caused by: java.lang.ClassNotFoundException: MLMain
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(

Ok. Before you say "Oh hurr durr you gotta add a class path". I tried, it doesn't work, just gives me "BLAH" no matter what I do.

I'm using Mac OS X Snow Leopard.

Output from
jar -tf mewLog_MacOSX-x86.jar

jar -tf mewLog_MacOSX-x86.jar

Answer Source


java -cp mewLog_macosx-x86.jar mewlog.MLMain


if so then your manifest file in the Jar is pointing to the wrong Main-Class (Not taking the package into account)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download