苏州专业网站建设设计,企业网站建设一般原则,昆明汽车建站网站模板,平面设计做兼职网站如果需要在一个构件文件中通过Ant命令去执行另一个Ant项目#xff0c;或者说要执行本项目的子项目的构件文件。这时Ant这个核心任务就派上用场了。简单地说Ant任务的作用就相当于在命令行通过Ant命令执行构件文件。值得注意的是Ant任务依赖于target元素#xff0c;需要在某个… 如果需要在一个构件文件中通过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: ?xml version1.0? project defaultrun basedir. nameMyProject property fileuser.properties/ target namerun ant antfile${file1} dir. outputfile1.log targetcall/ ant antfile${file2} dir. / ant antfile${file3} dir. / /target /project build1.xml ?xml version1.0? project defaultinit basedir. nameMyProject1 target nameinit echo messageThis is in Project1s init target./ /target target namecall echo messageThe call in Project1/ /target /project build2.xml ?xml version1.0? project defaultcall basedir. nameMyProject2 target nameinit echo messageThis is in Project2s init target./ /target target namecall dependsinit echo messageThe call in Project2/ /target /project build3.xml ?xml version1.0? project defaultcall basedir. nameMyProject3 target nameinit echo messageThis is in Project3s init target./ /target target namecall echo messageThe call in Project3/ /target /project file.properties file1build1.xml file2build2.xml file3build3.xml 运行结果 Buildfile: C:\hxw\workspace\hibernate\build.xml run: call: [echo] The call in Project1 init: [echo] This is in Project2s init target. call: [echo] The call in Project2 call: [echo] The call in Project3 BUILD SUCCESSFUL Total time: 78 milliseconds 转载于:https://blog.51cto.com/hongxuwei/649384