编译打jar包运行程序的一个完整例子
<?xmlversion=encoding=UTF?>
<projectname=HelloWorlddefault=runbasedir=>
<propertyname=srcvalue=src/>
<propertyname=destvalue=classes/>
<propertyname=hello_jarvalue=hellojar/>
<targetname=init>
<mkdirdir=${dest}/>
</target>
<targetname=compiledepends=init>
<javacsrcdir=${src}destdir=${dest}/>
</target>
<targetname=builddepends=compile>
<jarjarfile=${hello_jar}basedir=${dest}/>
</target>
<targetname=rundepends=build>
<javaclassname=testantHelloWorldclasspath=${hello_jar}/>
</target>
<targetname=clean>
<deletedir=${dest}/>
<deletefile=${hello_jar}/>
</target>
<targetname=rerundepends=cleanrun>
<anttarget=clean/>
<anttarget=run/>
</target>
</project>
若干个模块分别都已经有了上面的buildxml和源代码可以用下面的buildxml集成它们
<?xmlversion=encoding=UTF?>
<projectname=maindefault=buildbasedir=>
<propertyname=binvalue=${basedir}\bin/>
<propertyname=srcvalue=${basedir}\src/>
<propertyname=srcvalue=${basedir}\src/>
<propertyname=srcvalue=${basedir}\src/>
<targetname=init>
<mkdirdir=${bin}/>
</target>
<targetname=run>
<antdir=${src}target=run/>
<antdir=${src}target=run/>
<antdir=${src}target=run/>
</target>
<targetname=clean>
<antdir=${src}target=clean/>
<antdir=${src}target=clean/>
<antdir=${src}target=clean/>
</target>
<targetname=builddepends=init>
<antdir=${src}target=build/>
<antdir=${src}target=build/>
<antdir=${src}target=build/>
<copytodir=${bin}>
<filesetdir=${src}>
<includename=*jar/>
</fileset>
<filesetdir=${src}>
<includename=*jar/>
</fileset>
<filesetdir=${src}>
<includename=*jar/>
</fileset>
</copy>
</target>
<targetname=rebuilddepends=buildclean>
<anttarget=clean/>
<anttarget=build/>
</target>
</project>
利用property简化属性
新建allproperties文件里面的内容
src=F:\\TestAnt\\blog\\src
src=F:\\TestAnt\\blog\\src
src=F:\\TestAnt\\blog\\src
然后在buildxml里这样写就可以了
<propertyfile=allproperties/>
<propertyname=binvalue=${basedir}\bin/>
利用include xml在多个buildxml里添加同样的内容
如includexml:
<?xmlversion=encoding=UTF?>
<propertyname=srcvalue=src/>
<propertyname=destvalue=classes/>
<targetname=test>
<anttarget=run/>
</target>
在buildxml里这样写
<?xmlversion=encoding=UTF?>
<!includeaxmlfileitcanbecommonpropertycanbealsoatarget>
<!DOCTYPEproject[
<!ENTITYsharevariableSYSTEMfile:/includexml>
]>
<projectname=HelloWorlddefault=runbasedir=>
<!usetheinclude>
&sharevariable;
</project>