如何以编程方式添加邮件任务的Ant库的依赖 [英] How to programmatically add Ant library dependencies for mail task

查看:168
本文介绍了如何以编程方式添加邮件任务的Ant库的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在负责我们的Ant构建脚本创建自动通知。这是这样,当有人推了部署,我们的团队可以自动收到关于它的电子邮件。

I've been tasked with creating automated notifications for our Ant build scripts. This is so that when someone pushes out a deployment, our team can automatically receive an email about it.

最明显的选择是使用 Ant的邮件任务,附带的Ant pdefined $ P $:

The obvious choice was to use Ant's mail task, which comes predefined with Ant:

<target name="notify" description="notify team">
    <mail subject="latest deployment">
        <from address="me@gmail.com" />
        <to address="jimmy@yahoo.com" />
        <message>A new build has been pushed out to prod</message>
    </mail>
</target>

不过,这将导致以下运行时异常:

However this results in the following runtime exception:

java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage

这是因为Ant的邮件任务依赖于 JavaMail的并的 JavaBeans激活框架,这显然不包括其分布的库。为什么蚂蚁会定义依赖于某个库的任务,但不包括图书馆我不清楚。

This is because Ant's mail task depends on JavaMail and JavaBeans Activation Framework, libraries which are apparently not included with its distribution. Why Ant would define a task that depended on a library but not include that library is unclear to me.

这问题已经对这个职位的讨论。根据问题的答案,似乎有两种解决方案。

This issue has already been discussed on this post: ant mail task using mail and activation jar in external location. Based on the answers there seem to be two solutions.

首先是手动将这些库依赖于蚁类路径。这可以通过使用 -lib 命令行参数来完成,或在Eclipse中可以使用窗口&GT; preferences&GT;蚂蚁&GT;运行&GT;全球条目,然后添加的mail.jar 的activati​​on.jar (我pretty肯定这相当于同样的事情, -lib ,纠正我,如果我错了)。但这种方法是不可取的我们团队,因为这意味着我们每个人都必须手动执行这些步骤。我正在寻找一种方式来简单地提交我的通知code,它应该在另一个Eclipse工作SVN安装更新后。

The first is to manually put these library dependencies on the ant classpath. This can be done using the -lib command line argument, or in eclipse one can use Window > Preferences > Ant > Runtime > Global Entries, and then add mail.jar and activation.jar (I'm pretty sure this amounts to the same thing as -lib, correct me if I'm wrong). But this solution is undesirable for our team because it would mean every one of us would have to manually carry out these steps. I'm looking for a way to simply commit my notification code, and it should work on another eclipse install after svn update.

在链接后的另一个解决方案提到了以编程方式做上述情况,从自身调用Ant的:

The other solution in the linked post mentions a way to do the above programmatically, by calling Ant from itself:

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

这里的问题是,Ant命令行工具显然只包含在完全安装,而不是Eclipse发行。所以,再一次有没有办法让它没有​​一些手动操作以任何想要使用邮件的任务工作。

The problem with this is that the Ant command line tool is apparently only included with the full install, not the eclipse distribution. So again there's no way to make it work without some manual action by anyone wanting to use the mail task.

有什么办法没有我增加另一个恼人的步骤的项目设置可以自动完成这一点?我真的不明白这是为什么这么难实现 - 它似乎像如果邮件任务的不是的$ P由蚂蚁pdefined $这会更容易些。希望我失去了一些东西。

Is there any way I can automate this without adding another annoying step to project setup? I really don't understand why this is so hard to achieve - it seems like if the mail task wasn't predefined by Ant this would be easier. Hopefully I'm missing something.

推荐答案

Mail是在ANT可选任务之一。要安装这些附加库ANT 1.7增加了一个fetch.xml脚本,调用如下:

Mail is one of the optional tasks in ANT. To install these additional libraries ANT 1.7 added a fetch.xml script, invoked as follows:

ant -f $ANT_HOME/fetch.xml -Ddest=user -Dm2.url=http://repo1.maven.org/maven2 

在Windows中,您可以尝试:

On windows you could try:

ant -f %ANT_HOME%/fetch.xml -Ddest=user -Dm2.url=http://repo1.maven.org/maven2 

有关完整说明,请参见 ANT手册文档

For a full explanation, see the ANT Manual documentation.

下面的ANT文件有一个安装-jar文件目标,可以用来安装由邮件任务使用的失踪ANT罐子。

The following ANT file has an install-jars target that can be used to install the missing ANT jars used by the mail task.

<project name="demo" default="notify">

    <target name="install-jars" description="Install ANT optional jars">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/mail.jar"       src="http://search.maven.org/remotecontent?filepath=javax/mail/mail/1.4.4/mail-1.4.4.jar"/>
        <get dest="${user.home}/.ant/lib/activation.jar" src="http://search.maven.org/remotecontent?filepath=javax/activation/activation/1.1/activation-1.1.jar"/>
    </target>

    <target name="notify" description="notify team">
        <mail subject="latest deployment">
            <from address="me@gmail.com" />
            <to address="jimmy@yahoo.com" />
            <message>A new build has been pushed out to prod</message>
        </mail>
    </target>

</project>

我发现ANT邮件任务负载的任务是从ANT系统类路径依赖类。这意味着在构建在两个步骤来运行:

I discovered that the ANT mail task task loads it's dependent classes from the ANT system classpath. This means the build has to be run in two steps:

$ ant install-jars
$ ant

大多数ANT任务允许你指定一个类路径引用。该邮件任务没有。试图研究这个问题使我下面的邮件列表线程:

Most ANT tasks allow you to specify a classpath reference. The Mail task does not. Trying to research this issue lead me to the following mailing list thread:

该解决方案是错综复杂的,不值得。我建议你​​与生活的不便......(安装-jar文件的目标只需要运行一次)

The solution is convoluted and not worth the effort. I'd recommend living with the inconvenience... (The install-jars target only needs to be run once)

这篇关于如何以编程方式添加邮件任务的Ant库的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆