java.lang.NoClassDefFoundError: javax/mail/MessagingException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15035548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:18:01  来源:igfitidea点击:

java.lang.NoClassDefFoundError: javax/mail/MessagingException

javajavamailnoclassdeffounderror

提问by user2101299

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).

我一直在开发一个程序,该程序使用 Javamail API 根据时间事件和特定条件发送电子邮件。该程序在 Eclipse(最新版本)中完美运行,javamail 和激活器 jar 位于构建路径中,javamail 的依赖项也是如此。当我将项目导出为 jar 并尝试运行它时,就会出现问题。(生成的堆栈跟踪与 Eclipse 构建路径中缺少 javamail jar 时的堆栈跟踪相同)。

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.run(Unknown Source)
at java.net.URLClassLoader.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.

谢谢您的帮助。

回答by mantrid

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

假设您将javamail其他依赖项放入与lib/导出的 jar相关的文件夹中,您必须在清单文件中声明这些 jar:

Class-Path: lib/javamail.jar

回答by djangofan

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

您还可以通过在此 url 添加软件 REPO 之一来获取 Java EE 库。

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

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