Ant运行的命令

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:

  • -lib jars in the order specified by the -lib elements on the command line
  • jars from ${user.home}/.ant/lib (unless -nouserlib is set)
  • jars from ANT_HOME/lib

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的描述我还没使用过。等下次遇到再说。

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惹不起的程咬金

来都来了,不赏点银子么

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值