注意点(2.1)

1.在命令行中运行多个目标

命令行: ant compile archive

<?xml version="1.0"?>
<project name="firstbuild" default="execute">
   <description>Compiles and runs a simple program</description>
   <target name="init">
       <mkdir dir="build/classes" />
	   <mkdir dir="dist" />
   </target>
   
 
   <target name="compile" depends="init" description="Compiles the source code">
       <javac srcdir="src" destdir="build/classes" />
    </target>
	
	
	<target name="archive" depends="compile" description="Creates the JAR file">
	   <jar destfile="dist/project.jar" basedir="build/classes" />
	</target>
	
	
	<target name="clean" depends="init" description="Removes the temporary directories used" >
	   <delete dir="build" />
	   <delete dir="dist"  />
	</target>
	
	<target name="execute" depends="compile" description="Runs the program" >
	   <echo level="warning" message="running"  />
	   <java
	      classname="org.antbook.welcome.Main"
		  classpath="build/classes">
		  <arg value="a" />
		  <arg value="b" />
		  <arg file="." />
	   </java>
	</target>
</project>

执行结果如下:

开发者可以在单一的构建中运行多个目标,只要在命令行上把这些目标一个接一个地列出来即可。但是当你再命令行上键入ant compile archive后会发生什么事情呢?很多人认为Ant会选择一个执行顺序,使得每个目标和它的依赖项只被执行一次:[init, compile, archive]。Unix的Make确实可以做到这一点,但是Ant不能。实际的情况是,Ant会依次执行每个目标和其依赖,所以真实的执行顺序是init,compile,然后是init,compile, archive。

猜你喜欢

转载自weigang-gao.iteye.com/blog/2169811