I’m making a java application that uses Javamail, and it works great when I compile it. I want to make it into a jar file so it can be easily moved around and executed. The problem is I am getting this error when I try to run the jar from the cmd line
java -jar ActriveTray2.jar
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Store
at stockApp.init(stockApp.java:11)
at ActiveTray.main(ActiveTray.java:31)
Caused by: java.lang.ClassNotFoundException: javax.mail.Store
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)
Here’s what’s in my jar file
- images/tray.gif
- META-INF/MANIFEST.MF
- ActiveTray.class
- ActiveTray.java
- config.class
- config.java
- GmailFetch.class
- GmailFetch.java
- stockApp$1.class
- stockApp.class
- stockApp.java
I think the issue is classpath, where the jar doesn’t know where the javamail jar lives. My classpath is set correctly when I execute the code (java ActiveTray2) it works fine… help 🙁
you need to add the jars you depend on to the manifest file, and also add them to the jar you are creating. java -jar will ignore your environment’s classpath, by design.
From the java docs:
so, you can add a line to your manifest file like:
to your manifest file.