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:

**mewLog**
- src/ (dir)
mewlog/ (package)
- MLGlobal.java
- MLMain.java (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 java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)


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
META-INF/MANIFEST.MF
.project
.classpath
mewlog/MLGlobal.class
mewlog/MLMain.class

Answer Source

does

java -cp mewLog_macosx-x86.jar mewlog.MLMain

work?

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