Programming Ant

 

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

    <path id="test.dist.dir.temp">
 

    <pathelement location="${test.dist.dir}" />

    <pathelement location="${dist.dir}" />

</path>

5, method target anywhere for reuse

    <target name="dotest">

        <someoperate />

    </target>

<target name="TestMemoryLeak">
<antcall target="dotest">
<param name="propfile" value="mem-leak.properties" />
<param name="testclass" value="MemoryLeakTest" />
</antcall>
</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()):

KeyDescription of Associated Value
java.versionJava Runtime Environment version
java.vendorJava Runtime Environment vendor
java.vendor.urlJava vendor URL
java.homeJava installation directory
java.vm.specification.versionJava Virtual Machine specification version
java.vm.specification.vendorJava Virtual Machine specification vendor
java.vm.specification.nameJava Virtual Machine specification name
java.vm.versionJava Virtual Machine implementation version
java.vm.vendorJava Virtual Machine implementation vendor
java.vm.nameJava Virtual Machine implementation name
java.specification.versionJava Runtime Environment specification version
java.specification.vendorJava Runtime Environment specification vendor
java.specification.nameJava Runtime Environment specification name
java.class.versionJava class format version number
java.class.pathJava class path
java.library.pathList of paths to search when loading libraries
java.io.tmpdirDefault temp file path
java.compilerName of JIT compiler to use
java.ext.dirsPath of extension directory or directories
os.nameOperating system name
os.archOperating system architecture
os.versionOperating system version
file.separatorFile separator ("/" on UNIX)
path.separatorPath separator (":" on UNIX)
line.separatorLine separator ("/n" on UNIX)
user.nameUser's account name
user.homeUser's home directory
user.dirUser'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...)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值