Learn about Ant's notes, according to the official web site example
<?xml version= "1.0"?>
<project name= "Ant-project" default= "Print-dir" >
<property name= "Name" value= "JoJo"/>
<target name= "Print-dir" >
<echo message= "Name: ${name} project: ${ant.project.name}"/>
</target>
</project>
The results of the operation are as follows:
[Email protected]_test apache-ant-1.9.7]# bin/ant-f/home/huang/test/build.xml
BuildFile:/home/huang/test/build.xml
Print-dir:
[Echo] Name:jojo project:ant-project-----"${ant.project.name}, System variable
BUILD Successful
Total time:0 seconds
In the example above, the user has set a property named Name, which is set and can be obtained by ${name} later in this article.
Unzip parameters:
[Email protected]_test test]# Cat Unzip.xml
<project name= "Unzip_name" default= "init" >
<property name= "Src.dir" value= "/home/huang/test/src"/>
<property name= "Dest.dir" value= "/home/huang/test/dest"/>
<target name= "Init" description= "compress the Task" >
<unzip src= "${src.dir}/build.zip" dest= "${dest.dir}"/>
</target>
</project>
mkdir Create a src directory: http://ant.apache.org/manual/Tasks/mkdir.html
[Email protected]_test test]# Cat File.xml
<project name= "Create" default= "number" basedir= "/home/huang/test" >
<property name= "Src.dir" value= "src"/>
<target name= "Number" >
<mkdir dir= "${src.dir}"/>
</target>
</project>
Operation Result:
[Email protected]_test apache-ant-1.9.7]# bin/ant-f/home/huang/test/file.xml
BuildFile:/home/huang/test/file.xml
Number
[MkDir] Created dir:/home/huang/test/src
BUILD Successful
Total time:0 seconds
Delete Deletes a directory or file: http://ant.apache.org/manual/Tasks/delete.html
[Email protected]_test test]# Cat File.xml
<project name= "Create" default= "number" basedir= "/home/huang/test" >
<property name= "Src.dir" value= "src"/>
<target name= "Number" >
<delete dir= "${src.dir}"/>
</target>
</project>
Operation Result:
[Email protected]_test apache-ant-1.9.7]# bin/ant-f/home/huang/test/file.xml
BuildFile:/home/huang/test/file.xml
Number
[Delete] Deleting directory/home/huang/test/src---Delete all files in the SRC directory and its directory
BUILD Successful
Total time:0 seconds
Delete files with a. bak end in the directory
<delete>
<fileset dir= "." includes= "**/*.bak"/>----"Delete the file that has the. bak in the word directory below the current directory
</delete>
Copy copies a file: http://ant.apache.org/manual/Tasks/copy.html
[Email protected]_test test]# Cat File.xml
<project name= "Create" default= "number" basedir= "/home/huang/test" >
<property name= "Src.dir" value= "src"/>
<target name= "Number" >
<copy file= "Unzip.xml" tofile= "unzip.xml_copy"/>----"Copy a single file unzip.xml,unzip.xml_copy
</target>
</project>
Operation Result:
[Email protected]_test apache-ant-1.9.7]# bin/ant-f/home/huang/test/file.xml
BuildFile:/home/huang/test/file.xml
Number
[Copy] Copying 1 File To/home/huang/test
BUILD Successful
Total time:0 seconds
<copy file= "Unzip.xml" todir= "${src.dir}"/> Copy the single file to the directory
[Email protected]_test test]# ll src/
Total 4
-rw-r--r--1 root root 293 Sep 14:53 unzip.xml
Copy copies all files in a directory except for a specific file: http://ant.apache.org/manual/Tasks/copy.html
[Email protected]_test test]# Cat File.xml
<project name= "Create" default= "number" basedir= "/home/huang/test" >
<property name= "Src.dir" value= "src"/>
<property name= "Dest.dir" value= "Dest"/>
<target name= "Number" >
<mkdir dir= "${dest.dir}"/>
<copy todir= "${dest.dir}" >
<fileset dir= "${src.dir}" excludes= "**/*.xml"/>----"excludes: Exclude a specific file
</copy>
</target>
</project>
Run as follows:
[Email protected]_test apache-ant-1.9.7]$ bin/ant-f/home/huang/test/file.xml
BuildFile:/home/huang/test/file.xml
Number
[Copy] Copying 1 File To/home/huang/test/dest
BUILD Successful
Total time:0 seconds
Copy copy all files under a directory to. bak mode
[Email protected]_test test]$ Cat File.xml
<project name= "Create" default= "number" basedir= "/home/huang/test" >
<property name= "Src.dir" value= "src"/>
<property name= "Dest.dir" value= "Dest"/>
<target name= "Number" >
<copy todir= "${dest.dir}" >
<fileset dir= "${src.dir}"/>
<globmapper from= "*" to= "*.bak"/>
</copy>
</target>
</project>
The results are as follows:
[Email protected]_test apache-ant-1.9.7]$ bin/ant-f/home/huang/test/file.xml
BuildFile:/home/huang/test/file.xml
Number
[Copy] Copying 2 Files To/home/huang/test/dest
[Copy] Copied 1 Empty directory to 1 empty directory Under/home/huang/test/dest
BUILD Successful
Total time:0 seconds
[Email protected]_test test]$ ll dest/
Total 4
-rw-rw-r--1 Huang Huang 0 Sep 15:40 Test.txt.bak
-rw-rw-r--1 Huang Huang 293 Sep 15:40 Unzip.xml.bak
The compile and run process for a jar program:
<project name= "HelloWorld" basedir= "/home/huang/test/" default= "main" >
<property name= "Src.dir" value= "src"/>
<property name= "Build.dir" value= "Build"/>
<property name= "Classes.dir" value= "${build.dir}/classes"/>
<property name= "Jar.dir" value= "${build.dir}/jar"/>
<property name= "Main-class" value= "Oata. HelloWorld "/>
<target name= "clean" >
<delete dir= "${build.dir}"/>
</target>
<target name= "Compile" >
<mkdir dir= "${classes.dir}"/>
<javac srcdir= "${src.dir}" destdir= "${classes.dir}"/>
</target>
<target name= "Jar" depends= "compile" >
<mkdir dir= "${jar.dir}"/>
<jar destfile= "${jar.dir}/${ant.project.name}.jar" basedir= "${classes.dir}" >
#######${ant.project.name}----->helloworld (<project name= "HelloWorld")
<manifest>
<attribute name= "Main-class" value= "${main-class}"/>
</manifest>
</jar>
</target>
<target name= "Run" depends= "jar" >
<java jar= "${jar.dir}/${ant.project.name}.jar" fork= "true"/>
</target>
<target name= "Clean-build" depends= "Clean,jar"/>
<target name= "main" depends= "Clean,run"/>
</project>
Now it's easier, just do a ant and you'll get
Buildfile:build.xml
Clean
Compile
[MkDir] Created dir:c:\...\build\classes
[Javac] Compiling 1 source file to C:\...\build\classes
Jar:
[MkDir] Created Dir:c:\...\build\jar
[Jar] Building Jar:c:\...\build\jar\helloworld.jar
Run
[Java] Hello World
Main
BUILD Successful
Automatic Deployment Tools Ant