java.lang.ClassNotFoundException:javax.mail.MessagingException

2024-05-15

我想使用 eclipse 将电子邮件从我的 gmail 帐户发送到另一个邮件帐户。我使用 apache tomcat 7.0.34 作为我的 Web 服务器,并使用端口 8080 作为 apache 服务器(HTTP/1.1),并使用 JRE 7 作为系统库在Java 资源下的库中包含mail.jar 和activation.jar。

下面给出了我的 jsp 页面,其中输入收件人地址并提交到服务器。

发送邮件.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Insert title here</title>
    </head>
    <body>
        <form action="ControllerMail">
            Recipient Address : <input type="email" name="to" ><br/><br/>
            <input type="submit" value="Submit"/>
            <input type="hidden" name="pageType" value="sendmail"/>
        </form>
    </body>
</html>

现在,我的 servlet 类如下所示。

控制器邮件.java

package com.sendmail.controller;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ControllerMail extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public ControllerMail() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doProcess(request,response);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doProcess(request,response);
    }

    protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
        String pageType = request.getParameter("pageType");
        if(pageType.equals("SendMail"))
        {
            String to = request.getParameter("to");

            //Get the session object
              Properties props = new Properties();
              props.put("mail.smtp.host", "localhost");
              props.put("mail.smtp.socketFactory.port", "465");
              props.put("mail.smtp.socketFactory.class",
                        "javax.net.ssl.SSLSocketFactory");
              props.put("mail.smtp.auth", "true");
              props.put("mail.smtp.port", "465");

              Session session = Session.getDefaultInstance(props,
               new javax.mail.Authenticator() {
               protected PasswordAuthentication getPasswordAuthentication() {
               return new PasswordAuthentication("********@gmail.com","********");//change accordingly
               }
              });

            //compose message
              try {
               MimeMessage message = new MimeMessage(session);
               message.setFrom(new InternetAddress("********@gmail.com"));//change accordingly
               message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
               message.setSubject("Greetings");
               message.setContent("Hi,what's up","text/html");

               //send message
               Transport.send(message);

               System.out.println("message sent successfully");

              } catch (MessagingException e) {throw new RuntimeException(e);}
        }
    }

}

但是当我在服务器上运行我的项目时,这意味着当我右键单击我的 SendMail.jsp 页面并单击“在服务器上运行”时,会发生以下错误。

Mar 17, 2015 7:41:38 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Program Files\PC Connectivity Solution\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_75\bin;F:\Software\JavaMailAPI\activation-jaf1.1.1.jar;F:\Software\JavaMailAPI\java-mail-1.4.4.jar;F:\Software\eclipse-jee-luna-SR1a-win32\eclipse;;.
Mar 17, 2015 7:41:39 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SendEmail' did not find a matching property.
Mar 17, 2015 7:41:39 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8081"]
Mar 17, 2015 7:41:39 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mar 17, 2015 7:41:39 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 539 ms
Mar 17, 2015 7:41:39 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 17, 2015 7:41:39 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.34
Mar 17, 2015 7:41:39 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SendEmail]]
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SendEmail]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 6 more
Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Unknown Source)
    at java.lang.Class.getDeclaredFields(Unknown Source)
    at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:87)
    at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:261)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:67)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:405)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    ... 20 more

Mar 17, 2015 7:41:39 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:684)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:451)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more

Mar 17, 2015 7:41:39 PM org.apache.catalina.startup.Catalina start
SEVERE: Catalina.start: 
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:684)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:451)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 11 more

Mar 17, 2015 7:41:39 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 249 ms

45秒后,将显示一个对话框,显示“在本地主机上启动Tomcat V7.0服务器”遇到问题。


java.lang.NoClassDefFoundError: javax/mail/MessagingException

Add the mail.jar http://www.oracle.com/technetwork/java/javamail/index-138643.html例如在您的 tomcat lib (/catalina_home/commons/libs/) 或您的 Web 应用程序文件中(请参阅 web-inf/lib)。

您还可能需要激活罐 http://www.oracle.com/technetwork/java/jaf11-139815.html.

最新的 javax.mail.jar 请参阅https://java.net/projects/javamail/pages/Home https://java.net/projects/javamail/pages/Home

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java.lang.ClassNotFoundException:javax.mail.MessagingException 的相关文章

随机推荐

  • ASP.NET AJAX 4.0 客户端数据绑定

    我在 MSDN 杂志上读到了一些有关 ASP NET AJAX 4 0 新功能的文章 主要是客户端数据绑定 我觉得 MSDN 杂志有时包含很多 营销 所以我对真正开发人员的意见很感兴趣 值得吗 您打算使用它吗 Edit 如果有人感兴趣的话
  • PostgreSQL:比较 json [重复]

    这个问题在这里已经有答案了 众所周知 目前 PostgreSQL 还没有方法来比较两个 json 值 比较就像json json不起作用 但是选角呢json to text before Then select x a y b json t
  • Laravel Homestead 中 npm 安装错误有解决方案吗?

    Windows 10 家园 虚拟盒6 0 8 流浪者2 2 5 节点 v12 5 0 npm v6 10 1 我想做的就是在新安装的 Laravel 应用程序中执行 npm install 命令 但我不断收到错误 经过两天的谷歌搜索并尝试了
  • iOS 解析如何通过 URL 下载文件

    我正在将 parse 用于我的聊天应用程序 当我上传文件时 我保留该 url 并将该 url 发送给其他用户 然后其他用户可以通过该 URL 下载文件 这是我上传文件的代码 void uploadBlob NSData blob fileN
  • 从 SQL Server 读取十进制值时出现溢出异常

    我想知道这是一个错误还是我做错了什么 我正在加载值SqlDataReader来自 SQL Server 2008 数据库 但在某些情况下 它无法将 SQL 值转换为 net 值 NET 4 0 我已将其追溯到一个测试用例 它演示了实际问题
  • 按值对 JSON 进行排序

    我有一个非常简单的 JSON 对象 如下所示 people f name john l name doe sequence 0 title president url google com color 333333 f name micha
  • Python 中上下文相关的日志级别

    我正在用 Python 制作一个 Web 应用程序框架的原型 主要是为了教育目的 但我一直坚持一个我一直想要的功能 每条路由的日志级别 此功能的目标是识别我们正在执行诊断的一些特定入口点 例如 我想跟踪呼叫者拨打电话时发生的情况POST s
  • 在 ActionScript 3 中在形状上绘制文本

    有没有办法仅使用 ActionScript 在 DisplayObject 或 Shape 中绘制文本 我在网上找到的唯一方法是创建 TextField 但我无法将 TF 添加到 DisplayObject 或 Shape Edit 解决了
  • 如何在Python中选择要写入(.csv)的列

    import csv f csv reader open lmt csv r open input file for reading Date Open Hihh mLow Close Volume zip f s plit it into
  • 如何修改 Amazon RDS 实例的 my.ini 参数

    在启动 MySQL 5 5 RDS 实例时 Amazon 使用默认参数组来配置 my ini 参数 但控制台不允许我修改它们 我怎样才能实现这个目标 例如默认将存储引擎设置为MyISAM或设置字符集 此处记录了这一点 http aws am
  • 如何修复“Oracle.EntityFrameworkCore 类型中的方法‘get_Info’没有实现”。

    我正在尝试通过 EW 连接到 Oracle DB 论方法OnConfiguring是错误 System TypeLoadException 程序集 Oracle EntityFrameworkCore Version 2 0 19 1 Cu
  • 如何实现 __eq__ 进行集合包含测试?

    我遇到了一个问题 我将一个实例添加到一个集合中 然后进行测试以查看该对象是否存在于该集合中 我已经覆盖了 eq 但在包含测试期间不会调用它 我必须覆盖吗 hash 反而 如果是这样 我将如何实施 hash 鉴于我需要对元组 列表和字典进行哈
  • ASP.NET MVC 3,如何正确制作主题

    我正在寻找有关如何以最佳方式在 MVC 3 中实现 主题 的输入 我想需要一个自定义视图引擎来负责定位视图文件等 我还希望主题系统是可扩展的 这样 如果它只是其中一个视图 我想更改其他视图 但仍使用默认值 有点像 Orchard 项目吗 想
  • Java Logger 未记录到 Netbeans 中的输出

    我正在 Netbeans 中使用 Maven 启动一个 Java 项目 我编写了一些代码来使用 Logger 类进行日志记录 但是 日志记录似乎不起作用 在程序开始时 我运行 Logger getLogger ProjectMainClas
  • 资产未考虑基本 href url - 未找到错误

    我刚刚在 Webform 项目中复制了 Angular 构建脚本 并将该项目部署到 IIS 中 注意 我只复制了脚本文件 没有单独部署在 IIS 中 我已将 Angular dist 文件夹复制到 Webform 项目的 Scripts 文
  • Azure 函数上的 Emgucv 版本 4.2

    我想在 Azure Function V3 中使用 EmguCv 版本 4 2 我创建了一个 Azure Function v3 Net Core 应用程序 从 Nuget 安装了 Emgu Cv 版本 4 2 0 3636 也从 Nuge
  • Dijkstra 谈“软件工程”[关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 埃兹格 迪杰斯特拉 Edsger D
  • 使用 setText 更改文本后如何更新屏幕?

    现在我正在使用以下代码来更新TextView txtMain setText new text 该代码执行后 屏幕不会更新新文本 有没有办法可以强制文本立即更新 该代码执行后 屏幕不会更新新文本 一旦您将控制权归还给 Android 就应该
  • Excel VBA 导出到文本文件。需要删除空行

    我有一个工作簿 使用以下脚本将其导出到文本文件 它工作正常 但是当我打开文本文件时 末尾总是有一个空行 这导致我在生成此文本文件后运行的另一个脚本出现问题 有关如何从导出中删除空行的任何帮助 Code Sub Rectangle1 Clic
  • java.lang.ClassNotFoundException:javax.mail.MessagingException

    我想使用 eclipse 将电子邮件从我的 gmail 帐户发送到另一个邮件帐户 我使用 apache tomcat 7 0 34 作为我的 Web 服务器 并使用端口 8080 作为 apache 服务器 HTTP 1 1 并使用 JRE