1 在command line里面运行不带任何参数:
Ant
Ant首先会在当前目录下寻找build.xml,并运行target中声明为default 属性的tag。
如果想使用其他的build文件作为build xml,可以使用参数-buildfile file
如在上一篇文章的例子中使用:
D:/HelloAntWorld>ant -buildfile buildtest.xml
Buildfile: D:/HelloAntWorld/buildtest.xml
init:
compile:
[javac] D:/HelloAntWorld/buildtest.xml:26: warning: 'includeantruntime' was
not set, defaulting to build.sysclasspath=last; set to false for repeatable buil
ds
jar:
all:
BUILD SUCCESSFUL
Total time: 0 seconds
D:/HelloAntWorld>
2 使用参数 -find:
你可以不指定build xml所在的位置,利用-find 命令来搜索。
如 ant -find test.xml
Ant首先需要在当前目录下寻找,如果未找到,则到父目录寻找直到被找到或者到达root目录。
如果在find后面不加文件名,则直接寻找build.xml
3在编译的时候使用properity,形式:
-Dproperty =value
If you specify a property that is also set in the build file , the value specified on the command line will override the value specified in the build file.
结合我们上一篇的例子,使用:
D:/HelloAntWorld>ant -Dclassdir=./test/classes
Buildfile: D:/HelloAntWorld/build.xml
init:
compile:
[javac] D:/HelloAntWorld/build.xml:26: warning: 'includeantruntime' was not
set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 1 source file to D:/HelloAntWorld/test/classes
jar:
[jar] Building jar: D:/HelloAntWorld/lib/HelloAntWorld.jar
all:
BUILD SUCCESSFUL
Total time: 1 second
D:/HelloAntWorld>
在之前生成的目录.class文件在classes下面,现在放在test/classes下面。
01/11/2011 09:40 PM <DIR> .
01/11/2011 09:40 PM <DIR> ..
01/11/2011 09:40 PM <DIR> ${dirs.base}
01/11/2011 03:23 PM 232 .classpath
01/11/2011 03:23 PM 389 .project
01/11/2011 03:24 PM <DIR> bin
01/11/2011 04:39 PM 1,042 build.xml
01/11/2011 04:39 PM 1,042 buildtest.xml
01/11/2011 04:40 PM <DIR> lib
01/11/2011 03:24 PM <DIR> src
01/11/2011 09:34 PM <DIR> test
4 File(s) 2,705 bytes
7 Dir(s) 449,645,449,216 bytes free
4 关于build过程中的输出:
-quiet
, which instructs Ant to print less information to the console;
-verbose
, which causes Ant to print additional information to the console;
-debug
, which causes Ant to print considerably more additional information.
D:/HelloAntWorld>ant -quiet
[javac] D:/HelloAntWorld/build.xml:26: warning: 'includeantruntime' was not
set, defaulting to build.sysclasspath=last; set to false for repeatable builds
BUILD SUCCESSFUL
Total time: 0 seconds
可以看到信息明显减少
而下面的例子则可以看到信息明显增多。这个参数在perl和python中也有类似的作用。
D:/HelloAntWorld>ant -verbose
Apache Ant version 1.8.1 compiled on April 30 2010
Trying the default build file: build.xml
Buildfile: D:/HelloAntWorld/build.xml
Detected Java version: 1.4 in: C:/Program Files/IBM/Java142/jre
Detected OS: Windows XP
parsing buildfile D:/HelloAntWorld/build.xml with URI = file:/D:/HelloAntWorld/b
uild.xml
Project base dir set to: D:/HelloAntWorld
Build sequence for target(s) `all' is [init, compile, jar, all]
Complete build sequence is [init, compile, jar, all, clean, ]
init:
parsing buildfile jar:file:/C:/apache-ant-1.8.1/lib/ant.jar!/org/apache/tools/an
t/antlib.xml with URI = jar:file:/C:/apache-ant-1.8.1/lib/ant.jar!/org/apache/to
ols/ant/antlib.xml from a zip file
[mkdir] Skipping D:/HelloAntWorld/classes because it already exists.
[mkdir] Skipping D:/HelloAntWorld/lib because it already exists.
compile:
[javac] D:/HelloAntWorld/build.xml:26: warning: 'includeantruntime' was not
set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] example/HelloWorld.java omitted as D:/HelloAntWorld/classes/example/
HelloWorld.class is up to date.
jar:
[jar] example/HelloWorld.class omitted as D:/HelloAntWorld/lib/HelloAntWor
ld.jar:example/HelloWorld.class is up to date.
[jar] example omitted as D:/HelloAntWorld/lib/HelloAntWorld.jar:example/ i
s up to date.
[jar] No Implementation-Title set.No Implementation-Version set.No Impleme
ntation-Vendor set.
[jar] Location: D:/HelloAntWorld/build.xml:18:
all:
BUILD SUCCESSFUL
Total time: 0 seconds
5 Ant -projecthelp
The
-projecthelp
option prints out a list of the build file's targets.
D:/HelloAntWorld>ant -projecthelp
Buildfile: D:/HelloAntWorld/build.xml
Main targets:
Other targets:
all
clean
compile
init
jar
Default target: all
关于Ant执行时候的更多的参数可以参看下面或者help
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:/Documents and Settings/Administrator>Ant -h
ant [options] [target [target2 [target3] ...]]
Options:
-help, -h print this message
-projecthelp, -p print project help information
-version print the version information and exit
-diagnostics print information that might be helpful to
diagnose or report problems.
-quiet, -q be extra quiet
-verbose, -v be extra verbose
-debug, -d print debugging information
-emacs, -e produce logging information without adornments
-lib <path> specifies a path to search for jars and classes
-logfile <file> use given file for log
-l <file> ''
-logger <classname> the class which is to perform logging
-listener <classname> add an instance of class as a project listener
-noinput do not allow interactive input
-buildfile <file> use given buildfile
-file <file> ''
-f <file> ''
-D<property>=<value> use value for given property
-keep-going, -k execute all targets that do not depend
on failed target(s)
-propertyfile <name> load all properties from file with -D
properties taking precedence
-inputhandler <class> the class which will handle input requests
-find <file> (s)earch for buildfile towards the root of
-s <file> the filesystem and use it
-nice number A niceness value for the main thread:
1 (lowest) to 10 (highest); 5 is the default
-nouserlib Run ant without using the jar files from
${user.home}/.ant/lib
-noclasspath Run ant without using CLASSPATH
-autoproxy Java1.5+: use the OS proxy settings
-main <class> override Ant's normal entry point
C:/Documents and Settings/Administrator>
关于Ant的lib目录:
The default directories scanned are ANT_HOME/lib and a user specific directory, ${user.home}/.ant/lib. This arrangement allows the Ant installation to be shared by many users while still allowing each user to deploy additional jars.
The order in which jars are added to the classpath is as follows:
Note:
On Unix systems ${user.home} maps to the user's home directory whilst on recent versions of Windows it will be somewhere such as C:/Documents and Settings/username/.ant/lib
ant -lib one.jar -lib another.jar
不过以上关于lib的描述我还没使用过。等下次遇到再说。