I am new to Java and learning how to export applications to .jar files. I made a simple Java application in Eclipse with a few classes based on the tutorial from Eclipse and Java for Total Beginners.
When I run my application via Run -> Run in Eclipse, my application runs without exceptions. However, when I got to File -> Export and export my application into a .jar file and then execute
java myLibrary.jar
in my Mac terminal, I get this output from standard error.
Exception in thread "main" java.lang.NoClassDefFoundError: myLibrary/jar
Caused by: java.lang.ClassNotFoundException: myLibrary.jar
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
What does this mean? How am I missing classes? I tried checking and unchecking items to export. For instance, I tried including my JUnit tests to no avail.
In the terminal go to the directory that contains all your class files.
Then if the jar is created successfully you can run it by:
The MANIFEST.MF file should contain at the very least:
Where myLibrary is the class that contains your main function.