本文介绍了在外部位置使用邮件和激活 jar 的 ant 邮件任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下蚂蚁邮件任务 -

I have following ant mail task -

<target name="sendtestreport" > 
    <mail mailhost="smtp.com" mailport="1025" subject="Test build" >
        <from address="[email protected]" />           
        <replyto address="[email protected]" />
        <to address="[email protected]" />
        <message>test message</message>
        <attachments>
        </attachments>
    </mail>
</target>

我的项目lib"文件夹中同时提供了激活和邮件 jar.我希望能够发送邮件而不必将这些 jars 保存在 ant 下载位置.是否可以让 ant 知道我的lib"文件夹以查看 javaxmail 和激活 jars.一些类似如果我可以在这个目标中指定类路径的东西.

And I have both activation and mail jar available in my project "lib" folder. I want to be able to send mail with out having to keep these jars in ant download location. Is it possible to let ant know about my "lib" folder to see javaxmail and activation jars. Some thing like If I could specify class path from with in this target.

现在当我执行这个目标时总是遇到异常 -

Right now when I execute this target I always encounter exception -

BUILD FAILED
java.lang.ClassNotFound
Exception: javax.mail.internet.MimeMessage

推荐答案

不幸的是你不能.您必须以某种方式将 Library Dependencies 放入 ant 类路径中.

Unforunately you can't.You have to put Library Dependencies into the ant classpath somehow.

这可能是 ANTH_HOME/lib 目录或对命令行参数的更改.

This could be the ANTH_HOME/lib dir or a change to the command line arguments.

Ant 有一个 命令行参数 来指定一个 lib 目录:

Ant has a command-line argument to specify a lib dir:

-lib <path> specifies a path to search for jars and classes

您也可以使用该信息从 ant 本身调用 ant,这可能有点难看:

You could also call ant from ant itself with that info, which may be a bit ugly:

<exec executable="ant">
  <arg value="-lib"/>
  <arg value="PATH_TO_MY_LIB"/>
  <arg value="target"/>
</exec>

如果您从 Eclipse 执行此任务,则可以将库添加到任务的运行定义中,并与其他开发人员共享此运行定义.

If you execute this task from eclipse, you can add the libs to the run definition of the task and share this run definition with other developers.

这篇关于在外部位置使用邮件和激活 jar 的 ant 邮件任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 09:00