ANT1.6.1常用命令

来源:百度文库 编辑:神马文学网 时间:2024/04/29 08:49:59
 ANT1.6.1常用命令第一部分 基本结构
 

    
    
    
    

 
     
 

 
     
 

 
     
   
 

 
     
 


说明: 标准的XML文档, 根结点为project, 前面可以设置公有变量property, project中可含多个target, 每个target中可包括多个task.

------------------------------------

第二部分 应用程序基本结构

目录 文件
bin 公共的二进制文件, 以及运行脚本
build 临时创建的文件, 如类文件等
dist 目标输出文件, 如生成Jar文件等
doc/javadocs 文档
lib 需要导入的Java包, 即编辑过程中需要的包
src java源文件
web jsp, html等

------------------------------------

第三部分 核心TASK

1. copy
 拷贝单个文件
   

 拷贝单个文件到目录
   

 拷贝目录
   
     
   

 拷贝目录下指定文件(两种方式均可)
   
     
       
     
   

   
     
   

2. copydir
 拷贝目录
            dest="${dist}"
 />

 拷贝目录下指定内容
     dest="${dist}"
    includes="**/*.java"
    excludes="**/Test.java"
 />

     dest="${dist}"
    includes="**/*.java"
    excludes="mypackage/test/**"/>

3. copyfile 
 拷贝单个文件
 
 


4. cvs 
 从CVS服务器得到指定package的项目, 将之下载到dest指定目录下
          package="ant"
         dest="${ws.dir}"
 />

5. delete
 

 

 删除当前目录和所有子目录下的bak文件
 
 
 


 删除build下所有文件及子目录, 包括build目录本身也删除
 
 
 

 deletes all files and subdirectories of build, including build itself.

6. deltree 
 
 deletes the directory dist, including its files and subdirectories.

 
 deletes the directory ${dist}, including its files and subdirectories.

7. ear 
 
  
 


8. echo
 
  
 This is a longer message stretching over
 two lines.
 

  
 
 This is a longer message stretching over
 three lines; the first line is a blank
 

 
 只有当debug模式时才输出
 

9. exec
 执行某程序
 
 

 
     
 

10. import
 
 Imports targets from the common-targets.xml file that is in a parent directory.

 
 Imports the project defined by the property deploy-platform

11. input
 执行过程中请用户输入y/n, 根据输入做出不同操作
   message="All data is going to be deleted from DB continue (y/n)?"
  validargs="y,n"
  addproperty="do.delete"
 />
 
 
 
 Build aborted by user.

12. jar 
 

         basedir="${build}/classes"
        excludes="**/Test.class"
 />

         basedir="${build}/classes"
        includes="mypackage/test/**"
        excludes="**/Test.class"
 />


 
            excludes="**/Test.class"
 />
 
 

13. java 
 
         
         
           
           
         

        

14. javac 
    destdir="${build}"
   classpath="xyz.jar"
   debug="on"
 />
 compiles all .java files under the ${src} directory, and stores the .class files in the ${build} directory. The classpath used includes xyz.jar, and compiling with debug information is on.

      destdir="${build}"
   fork="true"
   />
 compiles all .java files under the ${src} directory, and stores the .class files in the ${build} directory. This will fork off the javac compiler using the default javac executable.

    destdir="${build}"
   fork="java$$javac.exe"
 />
 compiles all .java files under the ${src} directory, and stores the .class files in the ${build} directory. This will fork off the javac compiler, using the executable named java$javac.exe. Note that the $ sign needs to be escaped by a second one.

    destdir="${build}"
   includes="mypackage/p1/**,mypackage/p2/**"
   excludes="mypackage/p1/testpackage/**"
   classpath="xyz.jar"
   debug="on"
 />
 compiles .java files under the ${src} directory, and stores the .class files in the ${build} directory. The classpath used includes xyz.jar, and debug information is on. Only files under mypackage/p1 and mypackage/p2 are used. All files in and below the mypackage/p1/testpackage directory are excluded from compilation.

    destdir="${build}"
   includes="mypackage/p1/**,mypackage/p2/**"
   excludes="mypackage/p1/testpackage/**"
   classpath="xyz.jar"
   debug="on"
 />
 is the same as the previous example, with the addition of a second source path, defined by the property src2. This can also be represented using nested  elements as follows:

    classpath="xyz.jar"
   debug="on">
     
     
     
     
     
 
 If you want to run the javac compiler of a different JDK, you should tell Ant, where to find the compiler and which version of JDK you will be using so it can choose the correct command line switches. The following example executes a JDK 1.1 javac in a new process and uses the correct command line switches even when Ant is running in a Java VM of a different version:

    destdir="${build}"
   fork="yes"
   executable="/opt/java/jdk1.1/bin/javac"
   compiler="javac1.1"
 />
 指定了版本号

15. javadoc
     destdir="docs/api"
    author="true"
    version="true"
    use="true"
    windowtitle="Test API">

 
 
 
 

 Test]]>
 Copyright © 2000 Dummy Corp. All Rights Reserved.]]>
 
 
 
 http://java.sun.com/products/jdk/1.2/docs/api/" packagelistLoc="C:\tmp"/>
 http://developer.java.sun.com/developer/products/xml/docs/api/"/>
 

16. mail 
 
   
   
   
   The ${buildname} nightly build has completed
   
     
   
 

 Sends an eMail from config@myisp.com to all@xyz.com with a subject of Test Build. Replies to this email will go to me@myisp.com. Any zip files from the dist directory are attached.  The task will attempt to use JavaMail and fall back to UU encoding or no encoding in that order depending on what support classes are available. ${buildname} will be replaced with the buildname property‘s value.

17. mkdir 
 
 creates a directory ${dist}.

 
 creates a directory ${dist}/lib.

18. move 
 move与copy类似, 不同的是, 不留原稿
 Move a single file (rename a file)
 

 Move a single file to a directory
 

 Move a directory to a new directory
 
     
 

 Move a set of files to a new directory
 
     
       
       
     
 

 Append ".bak" to the names of all files in a directory.
 
     
       
     
     
 

19. property 
 
 sets the property foo.dist to the value "dist".

 
 reads a set of properties from a file called "foo.properties".
 从文件中获取, 把属性做成一个单独的文件

 http://www.mysite.com/bla/props/foo.properties"/>
 reads a set of properties from the address "http://www.mysite.com/bla/props/foo.properties".

20. rename 
 

21. replace
   file="configure.sh"
  value="defaultvalue"
  propertyFile="source/name.properties">
   token="@token1@"/>
   token="@token2@" 
 value="value2"/>
   token="@token3@" 
 property="property.key"/>
 

 In file configure.sh, replace all instances of "@token1@" with "defaultvalue", all instances of "@token2@" with "value2", and all instances of "@token3@" with the value of the property "property.key", as it appears in property file src/name.properties.

22. sleep 
 
 Sleep for about 10 mS. 

 
 Sleep for about 2 seconds. 

 
 Sleep for one hour less 59:58, or two seconds again 

 
 Sleep for no time at all. This may yield the CPU time to another thread or process. 

23. sql
      driver="org.database.jdbcDriver"
     url="jdbc:database-url"
     userid="sa"
     password="pass"
     src="data.sql"
 />

 Connects to the database given in url as the sa user using the org.database.jdbcDriver and executes the SQL statements contained within the file data.sql

      driver="org.database.jdbcDriver"
     url="jdbc:database-url"
     userid="sa"
     password="pass"
     >
 insert  into table some_table values(1,2,3,4);
 truncate table some_other_table;
 

      driver="org.database.jdbcDriver"
     url="jdbc:database-url"
     userid="sa"
     password="pass"
     >
 update some_table set column1 = column1 + 1 where column2 < 42;

 ]]>

      driver="org.database.jdbcDriver"
     url="jdbc:database-url"
     userid="sa"
     password="pass"
     src="data.sql"
     print="yes"
     output="outputfile.txt"
     >
 
  
 

 

24. subant
 
             
        

 
        
        
            
              
              
              
            
        
        

25. unjar/untar/unwar/unzip 
 

 
  


         dest="${tools.home}">
     
  
  
     

 

 

 
     
  
  
     

     
  
  
     
 

26. war 
 
 Assume the following structure in the project‘s base directory:

 thirdparty/libs/jdbc1.jar
 thirdparty/libs/jdbc2.jar
 build/main/com/myco/myapp/Servlet.class
 src/metadata/myapp.xml
 src/html/myapp/index.html
 src/jsp/myapp/front.jsp
 src/graphics/images/gifs/small/logo.gif
 src/graphics/images/gifs/large/logo.gif

 then the war file myapp.war created with 

 
   
   
   
     
   
   
           prefix="images"/>
 

 will consist of 
 WEB-INF/web.xml
 WEB-INF/lib/jdbc2.jar
 WEB-INF/classes/com/myco/myapp/Servlet.class
 META-INF/MANIFEST.MF
 index.html
 front.jsp
 images/small/logo.gif
 images/large/logo.gif