java.lang.NoClassDefFoundError: javax/mail/MessagingException

夙愿已清 提交于 2019-12-21 12:09:07

问题


I've been working on a program that uses the Javamail API to send emails based on time events and certain conditions. The program runs perfectly in Eclipse (newest version) and the javamail and activator jars are in the build path, as are javamail's dependencies. The problem occurs when I export the project as a jar and try to run it. (The stack trace generated is the same that would be if the javamail jar was missing from the Eclipse build path).

The stack trace is as follows:

`Exception in thread "Timer-1" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at SpaceCheck.HourlySpaceAlerts(SpaceCheck.java:212)
at WarningReports.run(WarningReports.java:21)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 4 more`

Thank you for your help.


回答1:


assuming you put javamail and other dependencies in to lib/ folder relative to your exported jar, you have to declare those jars in manifest file:

Class-Path: lib/javamail.jar



回答2:


You can also get Java EE libs by adding one of the software REPOs at this url.

http://download.eclipse.org/tools/orbit/downloads/



来源:https://stackoverflow.com/questions/15035548/java-lang-noclassdeffounderror-javax-mail-messagingexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!