Common Features
1, Initialized Project:
import java.io.File; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper;
public class InitializedProject extends Project { public InitializedProject(File buildFile) { super(); init(); ProjectHelper projectHelper = ProjectHelper.getProjectHelper(); addReference("ant.projectHelper", projectHelper); projectHelper.parse(this, buildFile); } } |
---|
2, Share properties with plain java code
<property file="userhome/some.properties" />
3, Organize layered build files or refer tasks/targets/properties in other build file for large scale application
<import file="../../../../../build/imports.xml" />
4, id anywhere for reuse
<pathelement location="${test.dist.dir}" />
<pathelement location="${dist.dir}" />
</path>
5, method target anywhere for reuse
<someoperate />
</target>
6, synchronized call
<target name="xdoclet" depends="init, xdoclet.ejb, xdoclet.test" />
6, script ant
although ant is not a script language, it does glue many operations together, it can combine any "executable programs", such as "Java Class", "OS script", "OS executable program", and ant scripts itself. ant also provides many useful tasks, you can use it instead of batch file.
Special Features for Large Scale Software
1, access environment variable:
<property environment="env"/> <echo message="Number of Processors = ${env.NUMBER_OF_PROCESSORS}"/> <echo message="ANT_HOME is set to = ${env.ANT_HOME}"/>
2, access JVM variable(http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#getProperties()):
-
Key Description of Associated Value java.version
Java Runtime Environment version java.vendor
Java Runtime Environment vendor java.vendor.url
Java vendor URL java.home
Java installation directory java.vm.specification.version
Java Virtual Machine specification version java.vm.specification.vendor
Java Virtual Machine specification vendor java.vm.specification.name
Java Virtual Machine specification name java.vm.version
Java Virtual Machine implementation version java.vm.vendor
Java Virtual Machine implementation vendor java.vm.name
Java Virtual Machine implementation name java.specification.version
Java Runtime Environment specification version java.specification.vendor
Java Runtime Environment specification vendor java.specification.name
Java Runtime Environment specification name java.class.version
Java class format version number java.class.path
Java class path java.library.path
List of paths to search when loading libraries java.io.tmpdir
Default temp file path java.compiler
Name of JIT compiler to use java.ext.dirs
Path of extension directory or directories os.name
Operating system name os.arch
Operating system architecture os.version
Operating system version file.separator
File separator ("/" on UNIX) path.separator
Path separator (":" on UNIX) line.separator
Line separator ("/n" on UNIX) user.name
User's account name user.home
User's home directory user.dir
User's current working directory
3, property is immutable
for large scale software development, all source files include ant build files would be committed to SCM system, but many configuration items are not same in every machine, such as Application Server setup folder and listening port; Combining "environment variable, jvm variable, and immutable property", ant provides a perfect solution for this, you can commit default property files to SCM, and put custom property file in your ${user.home}, as long as your build file would load property files in ${user.home} first.
(to be continue...)