Q:

java.lang.NoClassDefFoundError in command line

I'm developing an application in Eclipse and it runs fine from within Eclipse. The problem I'm having is that when I export it to a jar file and run it from the command line I get a NoClassDefFound error for javax.mail.internet.
In both my project build path and class path I have included the activation.jar and mail.jar libraries required for me to use javax.mail.internet, and like I said it works fine from within Eclipse but not when I export it to a jar. If my build path has those files and so does my class path why would this not be working?
Here is the error stack:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/mai
l/internet/InternetAddress
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.mail.internet.InternetAddress
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 27 more

A:

Wow I feel like a complete idiot. All you have to do is when exporting to a jar file instead of choosing "JAR File" in Eclipse choose "Runnable JAR File" and then tell it to package the required libraries in it to keep it small and wa-la, everything works nicely.
Another options is to add this line in the manifest file when the jar is being created:
Class-Path: lib/mail.jar
And then just have a lib folder with mail.jar in it within the same folder that the exported jar will be in. Boom.
The former option is the best in my opinion.

