蚂蚁 - 我如何可以运行相同取决于从多个目标 [英] Ant - How can I run the same depends from multiple targets

查看:107
本文介绍了蚂蚁 - 我如何可以运行相同取决于从多个目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让蚂蚁执行多个是否取决于目标多次。试想一下:

Is there a way to get ant to execute multiple depend targets multiple times. Consider this:

<target name="buildall" depends="mycommon,myDAO" />

<target name="myCommon" depends="initCommon, clean, makedir, compile" description="">
    <echo> Build completed for myCommon </echo>
</target>

<target name="myDAO" depends="initDAO, clean, makedir, compile" description="">
    <echo> Build completed for myDao </echo>
</target>

我想buildAll调用myCommon,这就要求initCommon,干净,MAKEDIR,编译,然后调用myDAO这就要求initDAO,干净,makedire,编译。

I would like buildAll to call myCommon, which calls initCommon, clean, makedir, compile, then call myDAO which calls initDAO, clean, makedire, compile.

所以,我要干净,MAKEDIR和编译要执行多次任务。他们是通用和运行基于initXXX任务设置属性。

So I want the clean, makedir and compile tasks to be executed multiple times. They are generic and run based on properties set in the initXXX task.

我试过这样:

<target name="buildall">
    <antcall  target="myCommon" />
    <antcall target="myDao" />
</target>

但在运行的任务,每次这不是我想要的东西之外的一切。有什么想法?

but that runs everything outside of tasks everytime which is not what I want. Any thoughts?

推荐答案

第一:不要使用&LT; antcall /&GT; 它通常是你已经做了一些迹象错了。

First: Do not use <antcall/> it's usually a sign you've done something wrong.

现在,明白,Ant是不是一种编程语言,你告诉Ant你想要做什么,你希望它做的顺序。 Ant是一个的矩阵依赖语言的。您只需告诉Ant你想要什么(我想建立这个jar),让蚂蚁搞清楚什么应该做的。蚂蚁做它最好的运行一个目标多次。

Now, understand that Ant is not a programming language where you tell Ant what you want to do and the order you want it to be done. Ant is a matrix dependency language. You merely tell Ant what you want (I want to build this jar), and let Ant figure out what it should do. Ant does its very best not to run a target multiple times.

例如,无论 myCommon myDAO 致电清洁目标。蚂蚁正式指出,都需要清洁目标,然后调用清洁一次,它都可以运行你的目标之前只有一次。这是蚂蚁是假设的工作方式。

For example, both myCommon and myDAO call the clean target. Ant duly notes that both require clean target, and then calls clean once and only once before it runs both of your targets. It's the way Ant is suppose to work.

因此​​,让蚂蚁完成其工作。首先,的你应不干净的在正常情况下。版本是假设,以尽量减少,以加快重建任务。如果你还没有修改的 *。java的文件,你为什么要强迫我来重建相应的 *类文件?

So, let Ant do its job. First, Thou shall not clean under normal circumstances. Builds are suppose to minimize rebuilding in order to speed up a task. If you haven't modified a *.java file, why should you force me to rebuild the corresponding *.class file?

第二:不要加倍的依赖关系:例如,如果我想建立目标 myDAO ,我想编译code(也许打造罐子或战争)。这就是我的 myDAO 目标应该依赖。现在,当我编译,我可能需要让我的目录,当我让我的目录,我可能需要做初始化我:

Second: Don't double up dependencies: For example, if I want to build the target myDAO, I want to compile the code (maybe build a jar or war). That's all my myDAO target should depend upon. Now, when I compile, I might need to make my directory, and when I make my directory, I might need to do my init:

<target name="clean">
    <echo>Clean up my working directory to be nice and sparkly</echo>
</target>
<target name="initDAO">
    <echo>Initialize stuff for my DAO build</echo>
    <echo>Maybe setup some properties?</echo>
</target>
<target name="makedir"
     depends="initDAO">
    <echo>I need my directories for building.</echo>
    <echo>But first, I need to setup stuff"</echo>
</target>
<target name="compile"
    depends="makedir">
    <echo>I need to compile my dao source"</echo>
    <echo>But first, I need to make the necessary directories</echo>
<target>
<target name="myDAO"
    depends="compile">
    <echo>Here's where I package up my DAO</echo>
    <echo>But I have to compile stuff before I can package it</echo>
</target>

请注意上述结构。如果我运行目标 myDAO ,蚂蚁会看的依赖,然后运行 initDAO MAKEDIR ,编译,最后 myDAO 的一切打包。再有,我有一个清洁目标将恢复我的工作空间以质朴(之前任何建)的条件,但我不把它作为一个包的一部分,因为我不想重做工作

Note the above structure. If I run the target myDAO, Ant will look at the dependencies and then run initDAO, makedir, compile, and finally myDAO to package everything up. Again, I have a clean target that will restore my working space to pristine (before anything was built) condition, but I don't call it as part of a package because I don't want to redo work.

啊!,你说,但我必须清理,因为 myCommon myDAO 使用相同的目录建筑和包装。

"Ah!", you say, "But I have to clean up because myCommon and myDAO use the same directories for building and packaging."

好了,不要做。相反,请确保您的两个包使用不同的目标的建筑和包装目录。这样,您就不必从一个到另一个收拾残局。而且,你可以改变一个源文件,重建,而不必重新编译一切。

Well don't do that. Instead, make sure your two packages use different target directories for building and packaging. This way, you don't have to clean up the mess from one to another. And, you can change a single source file, rebuild, and not have to recompile everything again.

您可以通过定义处理的东西,在普通两者之间的麻烦保存自己。例如,您可能能够定义一个编译宏作为它的参数源目录的名称,它会创建基于该源代码目录名的DESTDIR并编译您共同和 DAO 目标。

You can save yourself from trouble by defining macros to handle stuff in common between the two. For example, you might be able to define a compile macro that takes as its parameters the name of a source directory and it will create a destdir based upon that source directory name and compile your common and DAO targets.

所以,让蚂蚁工作它的魔力。使用依赖并不像蚂蚁讲如何做,而只是告诉蚂蚁,一个特定的目标取决于其他目标的一种手段。让蚂蚁搞清楚执行顺序。此外,不要设置你的任务,要求你擦洗目录和初始化的一切。你想Ant来帮助不必重建或重新复制了那些没有更改的文件最小化版本。

So, let Ant work its magic. Use dependencies not as a means of telling Ant how to do something, but merely telling Ant that a particular target depends upon another target. Let Ant figure out the order of execution. Also, don't set up your tasks to require you to scrub directories and reinitialize everything. You want Ant to help minimize the build by not having to rebuild or recopy over files that haven't changed.

这篇关于蚂蚁 - 我如何可以运行相同取决于从多个目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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