Getting javax.mail.MessagingException

I use javax.mail.jar to read email messages. But when I run the code, I get the following exception.

I added mail.jar to the 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(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) Could not find the main class: MasterProcess. Program will exit. 

Any suggestions to solve this problem, please ...

+4
source share
4 answers

You do not receive a MessagingException , the VM complains that it cannot find a MessagingException (although it is likely that it is looking for it because it wants to throw it, but this is a problem for later).

Check if your mail.jar really contains this class and check if your mail.jar is really in the classpath.

The last thing that can happen is that the class is incompatible with your version of Java. Classes compiled for 1.5 will not work, for example, on 1.4.

+1
source

Working in eclipse, and not on the command line, clearly indicates that there are several versions of the mailbox in the project.

Example:

You have 3 Jars, Jar X, Jar Y and Jar Z.

If you know that JAR X can already be connected inside JAR Z (in this case, the mailbox, but some other version.

So what is the problem with multiple versions of the same banner? You have two different versions, and you will not know what will be referenced in your project. (therefore, if you are looking for any class from mail-2.jar in your project, you will get a class exception not found if the link is made to mail-1.jar by the class loader)

So how does it work correctly on Eclipse? In eclipse you can see that there is an option for the ORDER library, it will be a link in the same order, but at run time on the command line we used to load as lib / *, which loads everything to assemble, and we won’t know which lib will load first.

How to identify the culprit and fix the problem?

Option 1:

See the docs page / user guide for the libraries you use to see what they have.

Option 2:

  • In eclipse, move the JAR in the question (mail.jar here) to TOP in the class order. (your program should work now)
  • Now leave the order one by one to find out where you got the error. (if you want to find a jar that causes this problem, duplicate the link)

  • Remove the jar that has the duplicate link, delete the duplicate inside the JAR and repack it. (If you want to)

+1
source

Also make sure you also have java activation. jar .

Do you accidentally work with an application server (for example, Jboss), if so, just check the class loading model (in jboss with one class loading model you can load the latest version of jars)

0
source

I also encountered the same error. It seems to me that when compiling I used the banks correctly. When I started on the command line, I noticed that mail.jar (javamail API) was not enabled.

0
source

All Articles