getting javax.mail.MessagingException
I am using javax.mail .jar file to read the mail messages. But when i m running the code i am getting the following exception.
I added mail.jar in classpath.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingE
xception
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.net.URLClassLoader$1.run(Unkn开发者_开发百科own 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)
Could not find the main class: MasterProcess. Program will exit.
any suggetionsn to solve this issue please ...
You're not getting a MessagingException
, the VM is complaining that it can't find MessagingException
(although it's probably that it's looking for it because it wants to throw it, but those are issues for later).
Check if your mail.jar actually contains this class, and check if your mail.jar really is on the classpath.
The last thing that could happen is that the class is incompatible with your version of Java. Classes compiled for 1.5 won't run on 1.4, for example.
Working in eclipse and not in command line clearly say that there is multiple versions of mail jar present in the project.
Ex:
You have 3 Jars , Jar X, Jar Y and Jar Z.
With out you knowing JAR X might be already be bundled inside JAR Z ( in this case mail jar but some different version.
So what is the problem in having multiple version of same jar ? You have two different versions and you will not know which will be referenced in your project. (so if you are looking for some class from mail-2.jar in your project you will get class not found exception if the reference is made to mail-1.jar by class loader)
So how come its working properly on Eclipse ? In eclipse you can see there is an option for ORDER the library, these will be reference in the same order, but while running in command prompt we used to load the as lib/* which loads all to gather and we will not know which lib will get loaded first.
How to identify the culprit and fix the issue ?
Option 1 :
See docs page / user guide of the libs you are using to see what they have in them.
Option 2 :
- In eclipse move the JAR in question (mail.jar here) to TOP in the class path order. (your program should work now)
Now bring down the order one by one to see where you get the error. (if you wish to find the jar which is causing this issue , duplicate reference)
Extract the jar which has the duplicate reference remove the duplicate inside the JAR and repackage it. (if required)
Also be sure you're having also the java activation.jar jar.
Are you by any chance working with an App Server (eg. Jboss), if so, just check classloading model (in jboss with single classloading model you may be loading a not so up-to-date version of the jars)
I've also faced the same error. It happens to me that while compiling i used the jars correctly. While running it on command line i noticed the mail.jar (javamail API) was not included.
精彩评论