简体   繁体   English

获取javax.mail.MessagingException

[英]getting javax.mail.MessagingException

I am using javax.mail .jar file to read the mail messages. 我正在使用javax.mail .jar文件读取邮件。 But when im running the code i am getting the following exception. 但是当我运行代码时,我得到以下异常。

I added mail.jar in classpath. 我在classpath中添加了mail.jar。

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 suggetionsn to solve this issue please ... 解决这个问题的任何建议请...

Working in eclipse and not in command line clearly say that there is multiple versions of mail jar present in the project. 在eclipse中而不是在命令行中工作清楚地表明项目中存在多个版本的mail jar。

Ex: 例如:

You have 3 Jars , Jar X, Jar Y and Jar Z. 您有3个罐,罐X,罐Y和罐Z。

With out you knowing JAR X might be already be bundled inside JAR Z ( in this case mail jar but some different version. 不知不觉中,您可能已经知道JAR X可能已经捆绑在JAR Z中(在这种情况下,为邮件罐,但版本有所不同)。

So what is the problem in having multiple version of same jar ? 那么,拥有多个版本的同一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) (因此,如果您在项目中的mail-2.jar中寻找某个类,那么如果类加载器对mail-1.jar进行了引用,则会导致找不到类异常)

So how come its working properly on Eclipse ? 那么它如何在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. 在eclipse中,您可以看到有一个ORDER库选项,这些库将以相同的顺序被引用,但是在命令提示符下运行时,我们曾使用过as as lib / *来加载所有要收集的as / lib,我们将不知道哪个lib将首先加载。

How to identify the culprit and fix the issue ? 如何确定问题的根源并解决问题?

Option 1 : 选项1 :

See docs page / user guide of the libs you are using to see what they have in them. 请参阅您正在使用的库的文档页面/用户指南,以了解它们所包含的内容。

Option 2 : 选项2:

  1. In eclipse move the JAR in question (mail.jar here) to TOP in the class path order. 在eclipse中,按类路径顺序将有问题的JAR(此处为mail.jar)移至TOP。 (your program should work now) (您的程序现在应该可以运行)
  2. 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) (如果您希望找到引起此问题的罐子,请重复参考)

  3. Extract the jar which has the duplicate reference remove the duplicate inside the JAR and repackage it. 提取具有重复引用的jar,删除JAR中的重复项并将其重新打包。 (if required) (如果需要的话)

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). 您没有得到MessagingException ,VM抱怨说它找不到 MessagingException (尽管可能是因为它想抛出它而正在寻找它,但这是以后要解决的问题)。

Check if your mail.jar actually contains this class, and check if your mail.jar really is on the classpath. 检查您的mail.jar是否实际上包含此类,并检查您的mail.jar是否确实在类路径上。

The last thing that could happen is that the class is incompatible with your version of Java. 可能发生的最后一件事是该类与您的Java版本不兼容。 Classes compiled for 1.5 won't run on 1.4, for example. 例如,为1.5编译的类不能在1.4上运行。

Also be sure you're having also the java activation.jar jar. 另外,请确保您还拥有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) 您是否有机会与App Server(例如Jboss)一起使用,如果是,只需检查类加载模型(在具有单个类加载模型的jboss中,您可能正在加载最新版本的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. 在命令行上运行它时,我注意到其中没有包括mail.jar(javamail API)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM