执行ant邮件任务时收到错误消息“java.lang.ClassNotFoundException:javax.mail.internet.MimeMessage”

时间:2013-06-25 16:36:15

标签: ant selenium-webdriver testng

我尝试执行下面提到的ant邮件任务,我收到错误消息:java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage

我为ant创建了环境变量。

还放置了mail.jar,激活jar& lib文件夹以及eclipse -> preferences -> Global Entries中的ant-javamail jar。执行ant邮件任务还需要其他什么吗?请建议。

<target description="Generates and send TestNG test reports" name="send-report">
    <mail mailhost="smtp.sears.com" mailport="25" user="kmart\vlakshm" password="AK230211$$" ssl="true" subject="Test build">
    <from address="vijayalakshmi.lakshmanan@searshc.com"></from>
     <replyto address="vijayalakshmi.lakshmanan@searshc.com"></replyto>
     <to address="vijayalakshmi.lakshmanan@searshc.com"></to>
     <message>Please find the attached report for Sears International smoke test results.</message>
         <attachments>
           <fileset dir="C:\\Documents and Settings\\vlakshm\\workspace\\INTL_REG\\test-output\\emailable-report.html">
            <include name="**/*.zip"/>
           </fileset>
         </attachments>
      </mail>
    </target>

在命令提示符下,执行下面提到的命令

ant send-report

获得下面提到的例外

build.xml:70: java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage

        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.apache.tools.ant.taskdefs.email.EmailTask.execute(EmailTask.java:
452)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
        at org.apache.tools.ant.Main.runBuild(Main.java:851)
        at org.apache.tools.ant.Main.startAnt(Main.java:235)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 0 seconds

1 个答案:

答案 0 :(得分:3)

在ANT_HOME / lib中添加mail.jar和activation.jar,或者使用两个jar形式的项目/ lib