ant 执行多个构建文件
2012-04-10 17:38
435 查看
如果需要在一个构件文件中通过Ant命令去执行另一个Ant项目,或者说要执行本项目的子项目的构件文件。这时Ant这个核心任务就派上用场了。简单地说Ant任务的作用就相当于在命令行通过Ant命令执行构件文件。值得注意的是Ant任务依赖于target元素,需要在某个target元素中使用,不能在target元素外独立使用。
Ant任务还可以实现类似Java程序间的继承关系,不过对于这个核心任务来说只继承property元素和reference属性。举个例子说,项目A中包含通过Ant任务去执行的项目B,而项目B中需要用到项目A中的属性C,那么可以通过设置的Ant任务中的inheritAll属性,使得在B项目中可以使用项目A中的属性C。从另一方面看,这也符合XP(极限)编程中的细分功能的思想,可以把大的项目切分为几分小项目,然后通过Ant工具进行整合。
项目结构:
project
-build.xml
-build1.xml
-build2.xml
-build3.xml
-file.properties
build.xml:
build1.xml
build2.xml
build3.xml
file.properties
运行结果:
本文出自 “坠落凡间的天使” 博客,请务必保留此出处/article/7377284.html
Ant任务还可以实现类似Java程序间的继承关系,不过对于这个核心任务来说只继承property元素和reference属性。举个例子说,项目A中包含通过Ant任务去执行的项目B,而项目B中需要用到项目A中的属性C,那么可以通过设置的Ant任务中的inheritAll属性,使得在B项目中可以使用项目A中的属性C。从另一方面看,这也符合XP(极限)编程中的细分功能的思想,可以把大的项目切分为几分小项目,然后通过Ant工具进行整合。
项目结构:
project
-build.xml
-build1.xml
-build2.xml
-build3.xml
-file.properties
build.xml:
<?xml version="1.0"?> <project default="run" basedir="." name="MyProject"> <property file="user.properties"/> <target name="run"> <ant antfile="${file1}" dir="." output="file1.log" target="call"/> <ant antfile="${file2}" dir="." /> <ant antfile="${file3}" dir="." /> </target> </project>
build1.xml
<?xml version="1.0"?> <project default="init" basedir="." name="MyProject1"> <target name="init"> <echo message="This is in Project1's init target."/> </target> <target name="call"> <echo message="The call in Project1"/> </target> </project>
build2.xml
<?xml version="1.0"?> <project default="call" basedir="." name="MyProject2"> <target name="init"> <echo message="This is in Project2's init target."/> </target> <target name="call" depends="init"> <echo message="The call in Project2"/> </target> </project>
build3.xml
<?xml version="1.0"?> <project default="call" basedir="." name="MyProject3"> <target name="init"> <echo message="This is in Project3's init target."/> </target> <target name="call"> <echo message="The call in Project3"/> </target> </project>
file.properties
file1=build1.xml file2=build2.xml file3=build3.xml
运行结果:
Buildfile: C:\hxw\workspace\hibernate\build.xml run: call: [echo] The call in Project1 init: [echo] This is in Project2's init target. call: [echo] The call in Project2 call: [echo] The call in Project3 BUILD SUCCESSFUL Total time: 78 milliseconds
本文出自 “坠落凡间的天使” 博客,请务必保留此出处/article/7377284.html
相关文章推荐
- 执行ant构建文件过后,没有修改任何相关的文件,第二遍执行ant,这时ant会提示任务已经完成的任务不再执行,记住这是任务级别的,这种情况包括在控制台上指定两个project
- Eclipse/MyEclipse设置在保存文件时自动调用Ant脚本执行一些构建操作
- ant 执行多个构建文件
- 这种情况既不是重复执行ant构建文件,也不是在控制台指定多个project,而是纯粹在构建文件有多个依赖关系
- Ant 构建文件的一种写法
- 利用 Ant 的 SQL Task 来实现自己的 Java 执行 SQL 脚本文件的功能
- 在的一个批处理(BAT)文件中成功执行多个ant命令的操作
- mkdir javac jar clean 不同情况执行构建文件的输出情况
- ant执行.class文件
- Ant系列九:使用Ant将java工程打包成bat可执行性文件 .
- 十七周四次课 2018.03.05 expect脚本同步文件、expect脚本指定host和要同步的文件、构建文件分发系统、批量远程执行命令
- 【ant项目构建学习点滴】--(3)打包及运行jar文件
- 使用ant 的exec时不能随意省略可执行文件的扩展名
- Ant构建文件解说
- 使用Ant将java工程打包成bat可执行性文件
- 整合ANT构建文件
- ant 构建文件路径
- ANT教程之三 Ant构建文件
- 使用ant的exec命令来调用 make命令执行makefile文件
- expect脚本同步文件、expect脚本指定host和要同步的文件、构建文件分发系统、批量远程执行