Introduction to the use of Ant

Keywords: Java ant

Introduction to the use of Ant

1. Introduction to Ant

    ApacheAnt is a Java-based construction tool. It is a tool that combines and automates the steps of software compilation, testing, deployment, etc., mostly for software development in a Java environment. Currently, the main Java ide s come with Ant, such as Eclipse, NetBeans, and IntelliJ IDEA.

    In theory, it's a bit like make, so why use another build tool since you already have make, gnumake, nmake, jam, and other tools? Because all these tools have some limitations (platform limitations), the original author of Ant cannot tolerate these limitations when developing software across multiple platforms. Instead of using a shell-based command extension model, Ant uses Java classes to extend. Instead of writing shell commands, the configuration file is XML-based, calling a target tree in which to perform various tasks. Each task is run by an object that implements a specific task interface.

2. Setting up the environment of Ant

2.1 Configuring environment variables

    Prerequisite: ANT's environment depends on JDK.

    (The newer the Java version, the more Ant tasks. Without a JDK, only the Runtime (JRE), many tasks will not work. If you run under windows, the bat script uses three environment variables: ANT_HOME, CLASSPATH, and JAVA_HOME.)

    ANT_ HOME to the directory where you unpacked Ant and ${ANT_HOME}/bin (Unix) or%ANT_HOME%\bin (Windows) added to your PATH.  

     You can also run the ant-diagnostics command to check if it is installed.

Version correspondence for 2.2, Ant, and JDK

     You can also run the ant-diagnostics command to check if it is installed.

2.3. Catalog description for Ant

After decompression:

  • bin: Includes starter scripts

  • docs:Ant Document

  • etc: Includes XSL, enhances output creation of various XML tasks, migrates and builds files

  • lib: contains Ant jar and necessary dependencies

              - Ant-junit.jar --> JUnit task-unit task

              - Ant-apache-bsf.jar-->script task-script task

              - Wait

  • README, LICENSE, fetch.xml, other text files.

3. Basic Use of Ant

    When we ran ant, we found the following tips: Because you need to write a build file for your project.

    Ant's build files are written in XML, each containing one project and at least one (default) target.

3.1. Introduction to Ant's construction label

3.1.1, Projects Tags

     The project tag is the root tag for each build file, and its semantics represent a project.

<!--project Label:An item that contains properties:
    1)name: Name of the project.
    2)default:Default target used when no target is provided. ( default="help",This target will always be executed as part of project initialization.
    3)basedir:Base Catalog,If not, the parent directory of the build file will be used.
-->
<project name="sunline-its" default="help" basedir=".">
</project>

3.1.2, description tag

    Item description information.

<project name="sunline-its" default="help" basedir=".">
    <description>Descriptive Information</description>
</project>

3.1.3, Targets Tags

    A target tag represents a build process or a task. An item tag can have one or more target tags underneath it. A target can depend on other target tags.

    For example, you might have a target for compilation and a target for creating distributable objects. Distributable objects can only be built after they are compiled first, so the distribution target depends on the compilation target. Ant resolves these dependencies.

    target is simply a container, a collection of instructions, a transaction.

<project name="MyProject" default="B" basedir=".">
   <!--
    target Tag: Target is a container, a collection of instructions, or a thing. Common attributes:
    1)name: Task name (required);
    2)depends: Dependency to execute the target Previously required target,Not required;
    3)description: Provide descriptive information, which can be-projecthelp Command line option output, not required;
    4)if: Execute this when the property is set target,Not required;
    5)unless: Execute the property when it is not set target,Not required.
   -->
   <target name="A" description="generate the distribution">...</target>
   <target name="B" depends="A">...</target>
   <!--a True if the property is configured, this task can be performed
       Note: if Only one attribute can be specified and multiple attributes can be used depends
    -->
   <target name="C" depends="A" if="a">...</target>
</project>

3.1.4, property tags

    The property tag is used to define a variable similar to that in a programming language, but it cannot be modified after it has been defined.

<!--
    property Common tag properties are as follows:
    1)name Represents the property name
    2)value Values representing attributes
    3)Some built-in properties:
        ant.home: Ant Home directory
        ant.project.default-target: It contains the name of the default target for the currently executing project
        ant.project.invoked-targets: Target list when calling current project
   Note:<property file="build.properties"/> Of course, you can also use a property file directly to define it
-->
<project name="MyProject" default="" basedir=".">
    <property name="name" value="mjx"/>
    <property name="age" value="25"/>
    <echo message="name: ${name}, age: ${age}"/>
    <echo message="${ant.home}"/>
</project>

Case effect:

3.2. How Ant works

    Ant runs in two common ways: using the command line and running in an integrated development environment (IDE) that supports Ant.

3.2.1, Run Ant from the command line

     Common command options for running from the command line:

<!--Use the current directory without any options build.xml file run Ant-->
ant 
<!--print the help information,-h For abbreviation-->
ant --help, -h  
<!--Print version information and exit-->
ant -version 

<!--Show current build.xml Main tasks and descriptive information-->
ant -projecthelp , -p 

<!--Diagnose or report problems-->
ant -diagnostics

<!--Specify Search jar And class paths-->
ant -lib <path> 

<!--Call execution is similar build.xml Files,- file,-f For abbreviation-->
ant -buildfile, - file,-f 

<!-- On the default target, use the test.xml file run Ant-->
ant -buildfile test.xml

<!-- In the name dist On the target, use the current directory test.xml file run Ant-->
ant -buildfile test.xml dist

<!--Used to set variables that can be repeated target Directly refers to or overrides a set property value in-->
ant -D<property>=<value>

3.2, Ant's Core Tasks (Standard Tasks or built-in Tasks)

    Ant has a lot of built-in command tasks, and of course allows us to customize them.

    Many standard tasks in ant use one or more file sets that follow the rules given here. This list is a subset of these lists. It is a list of standard ant tasks and can act as an implicit file set.

    The main built-in instructions are:

(     1) File operations

(     2) Code Compilation

(     3) Package deployment

(     Since other things are involved, here is a brief introduction to the file instructions task below.

3.2.1, mkdir Tags

     mkdir is used to create directories.

<!--Will create build/classes Catalog-->
<mkdir dir="build/classes"/>  

3.2.2, copy label

    The copy tag is used to copy files/directories.

<project name="MyProject" default="" basedir=".">
<!--Single file copy: will test.xml copy to dist Catalog-->
<copy file="test.xml" todir="dist"/>
<!--Single file copy: will test.xml copy to dist Catalog and rename it testnew.xml -->
<copy file="test.xml" tofile="dist/testnew.xml"/>
<!--Directory copy: will dist Copy directory to dist_copy -->
<copy todir="dist_copy">
       <!--Specify directory to copy-->
       <fileset dir="dist"/>
</copy>
</project>

Case effect:

3.2.3, delete tag

     Delete a file or directory.

<!--Delete a file-->
<delete file="/dist/test.xml"/>
<!--remove folders:Mode 1-->
<delete dir="dist"></delete>
<!--Mode 2: Delete the specified directory and its subdirectories, including himself
    includeEmptyDirs: Delete even empty directories, if not true Only delete files, not directories
-->
<delete includeEmptyDirs="true">
    <!--fileset Specify deleted directories and files-->
    <fileset dir="dist/lib"/>
</delete>

3.2.4, move Tags

     Move or rename a (group) file, directory.

<!--Move or rename a file-->
<move file="file.orig" tofile="file.moved"/>
<!--Move one directory to another-->
<move todir="new/dir/to/move/to">
    <fileset dir="src/dir"/>
</move>
<!--Increase while moving files bak Suffix-->
<move todir="dist/lib/.bak">
	<fileset dir="dist/lib/">
		<!--include Contain, exclude Does not contain, that is, except*.bak End File-->
	    <exclude name="*.bak"/>
	</fileset>
	<!--To Files Meet: Not*.bak End with suffix-->
	<mapper type="glob" from="*" to="*.bak"/>
</move>

Case effect:

3.3, Ant's Type Set

    In the above case, we touched on fileset, exclude, mapper tags. These tags are some of the type sets provided by Apache Ant that we can use to process data, files, paths, and so on, or as services. Types have two attributes, id and refid, which are the unique identities of the type. Refid is used to specify the type to be referenced and refid is the id of the type to be referenced. Types provided in official documents:

 

  Common set of types:

typedescribe
ClassFileSetJar for creating all required classes
DescriptionDescription Type
DirSetGrouping directories
FileListFile List
FileSetA set of files
File Mapper TypeUsed to map source and target files
FilterSetA set of filters
PatternSetDefine a collection of schemas (a set of schemas referenced by ids)
SelectorsFileSet elements help select elements
TarFileSettar file set, a special form of FileSet, starting with ant1.7
ZipFileSetFileset in zip format, Since Ant 1.6, supporting refid attribute

Other:

typedescribe
Extension/ExtensionSetRepresents a set of extended utility types (set extensions)
PermissionsRepresents granting or revoking permission to execute specific parts of code in a JVM running ApacheAnt.

All have properties:

typedescribe
idUnique identification of type
refidBecome a reference to a definition elsewhere. Specify the type to be referenced and the refid to be the id of the type to be referenced

3.3.1, ClassFileSet class file set

    ClassFileSet is a special type of FileSet that includes all the class files on which the root class depends. It is often used to create a jar for a particular application that contains all the required classes. Class file sets are typically used by reference. They are declared with an id value and then used as a reference where a common set of files is needed.

Use cases:

1) Step 1: Create a new HelloWorld.java

    Create a new com/cn/test directory and a new class in the dist directory.    

2) Step 2: Configure classFileType.xml

<project name="MyProject" default="cft" basedir=".">
    <!--id="reqdClasses": Is globally referenced id
	    dir="dist/class:  by com The directory where the directory is located-->
    <classfileset id="reqdClasses" dir="dist/class">
	    <!--com.cn.test.HelloWorld Class file set, using the entire folder*The end is fine-->
        <root classname="com.cn.test.HelloWorld"/>
    </classfileset>
    <target name="cft" description="ClassFileSet Demo">
		<classfileset id="reqdClasses" dir="dist/class">
		  <!--includes:Need to be packaged class File, type in HelloWorld*.class(HelloWorld.class Or its internal classes, etc.)-->
          <rootfileset dir="dist/class" includes="com/cn/test/HelloWorld*.class"/>
        </classfileset>
		<!--Package generated jar package-->
		<jar destfile="helloworld.jar">
          <fileset refid="reqdClasses"/>
        </jar>
	</target>
</project>

  3) Download dependent packages:

Tips on official website documents: This type requires the BCEL library.Download Link

Extensions, if additional features are required, can be downloaded:

Packages for ant developmentDownload Linkdescribe
bcel.jarhttps://commons.apache.org/bcel/Note Version: bcel-6.5.0 requires jdk8, you can download bcel-6.0
jython.jarhttps://www.jython.org/Python with script task
jakarta.mail.jarhttps://eclipse-ee4j.github.io/mail/
jruby.jarhttps://jruby.org/Ruby with script task

Case execution effect:          

3.3.2, Description Description Type

    The Description type does not contain any parameters and can be used within a target or in a global component file.

<description>
    This buildfile is used to build the Foo subproject within
the large, complex Bar project.
</description>

3.3.3, DirSet catalog set

    A catalog set is a set of directories. These directories can be found in the catalog tree starting from the base catalog and matched by patterns obtained from many pattern sets and selectors.

    A pattern set can be specified as a nested <patternset>element. In addition, DirSet holds implicit PatternSets and directly supports nested <include>, <includefile>, <exclude>, and <excludesfile> elements of <PatternSet> and attributes of <PatternSet>.

AttributeDescriptionRequired
dirThe root of the directory tree that owns this DirSetYes
includesList of catalog modesNo; defaults to all directories
includesfileName of the file to be includedNo
excludesList of directory modes that must be excludedNo; defaults to none
excludesfileName of file to excludeNo
casesensitiveUsed to specify whether case sensitivity should be appliedNo; defaults to true
followsymlinksThere is a symbolic link to followNo; defaults to true
erroronmissingdirIt specifies what happens if the base directory does not existNo; defaults to true (for backward compatibility reasons)

For example:

<!--Represents a directory: ${build.dir}So the name is apps/**/classes Directory without the name apps/**/*Test*Of-->
<dirset dir="${build.dir}">
  <include name="apps/**/classes"/>
  <exclude name="apps/**/*Test*"/>
</dirset>
<!--Choice ${workingdir}Include below ${markerfile}All files-->
<dirset id="dirset" dir="${workingdir}">
   <present targetdir="${workingdir}">
        <mapper type="glob" from="*" to="*/${markerfile}"/>
   </present>
</dirset>

3.3.4, FileList file list

    FileList is an explicitly named list of files. File sets act as filters that return only files that exist in the file system and match the specified pattern, while file lists are useful for specifying files that may or may not exist. Multiple files are specified as a list of files relative to the specified directory and wildcard extensions are not supported (file names with wildcards will be included in the list and will not be changed).

AttributeDescriptionRequired
dirBase directory for this file listYes
filesList of file names. This is a space- or comma-separated list of file names.Yes, unless there is a nested file element
refidName of the file to be includedNo

Use cases:

<!--Match: ${doc.src}/foo.xml or ${doc.src}/bar.xml-->
<filelist id="docfiles" dir="${doc.src}" files="foo.xml,bar.xml"/>
<!--Or place the above type somewhere else and match it by reference-->
<filelist refid="docfiles"/>

  3.3.5, FileSet set of files

    A FileSet is a set of files. These files can be found in the catalog tree starting from the base directory and matched by patterns obtained from many pattern sets and selectors. A pattern set can be specified as a nested <patternset>element. In addition, the file set holds the implicit schema set and directly supports nested <include>, <includefile>, <exclude> and <excludesfile> elements of the schema set and properties of the schema set.

AttributeDescriptionRequired
dirBase directory for this file listYes
fileUsed to specify a single file FileSetNo; defaults to yes
defaultexcludesIndicates whether default exclusion should be usedNo; defaults to all files
includesA list of file modes that must be included.No
includesfileFile name, containingNo;
excludesList of file modes that must be excludedNo;
excludesfileFile name, excludedNo;
casesensitiveinclude and exclude modes are case sensitive.No; defaults to true
followsymlinksSymbolic links should be followedNo; defaults to true
erroronmissingdirSpecify what happens if the base directory does not exist. If true, a build error will occur, and if false, the file set will be ignored/empty. Since ApacheAnt 1.7.1No; defaults to true

Use cases:

<!--Mode 1: Match: ${server.src}/And its subdirectories*.java But exclude inclusion Test Files-->
<fileset dir="${server.src}" casesensitive="yes">
  <include name="**/*.java"/>
  <exclude name="**/*Test*"/>
</fileset>

<!--Mode 2: You can also write like this-->
<fileset dir="${server.src}" casesensitive="yes">
  <filename name="**/*.java"/>
  <not>
    <filename name="**/*Test*"/>
  </not>
</fileset>

<!--Mode 3: You can also write like this-->
<fileset dir="src" includes="${server.src}/"/>

  3.3.6, File Mapper Type file mapping type

    The File Mapper type is used to specify the relationship between files. Sometimes after a task executes, the source file and output are different, then no mapping is done. Apache Ant uses FileMapper to map source and created target files.

AttributeDescriptionRequired
typeTo specify the type of a specific mapper implementation, the Ant tool provides built-in support, or you can write an implementation of a Mapper type. There are many types of types, such as identity, flatten, merge, glob, regexp, package, unpackage, composite, chained filtermapper, scriptmapper, first matchmapper, cutdirsmapperNo;
classnameSpecify an implementation class for Mapper through the classname property, and through this implementation class you need to implement Mapper's functionality. Both classname and type are required, and cannot be empty at the same timeNo; Exactly one of type or classname
classpathThe Java class library used to specify the lookup classname type is the classpath used to specify Java class dependenciesNo
classpathrefUsed to reference the classpath defined by the path element, which provides the class libraries on which compilation and operation dependNo
fromUsed to specify the location of the operation source, source fileDepends on implementation
toTarget for specified operationDepends on implementation

Use cases:

<!--
    type="identity" Don't do anything? fileset What is it?
    type="flatten"  The target file name is the same as the source file name, and all leading directory information is deleted. (Ignore path and invert file name only)
    type="merge" Merge, the target file name is always the same. stay git It is used to merge branches.
    type="glob"  Add prefix and suffix
    type="regexp" from and to Properties require and define regular expressions.
    type="package" and glob The grammar is the same, but packagemapper Replace the directory separator in the matching source pattern with."
    type="unpackage" Ant1.6 Introducing, and glob The grammar is the same, unpackage yes package Reverse.
    type="composite"  	Ant1.7 Introduce, composite Multiple can be nested mapper. 
    type="chained" Ant1.7 Introduce, chained Can contain multiple mapper. 
-->
<!--merge:Package files to archive.tar-->
<mergemapper to="archive.tar-->"/>
<!--glob,Backup Files,These types can be used in both ways-->
<!--Mode 1: Put all of the current directory's*.java,Map to Target Directory*.java.bak-->
<mapper type="glob" from="*.java" to="*.java.bak"/>
<!--Mode 2: Put all of the current directory*.java,Map to Target Directory*.java.bak-->
<globmapper from="*.java" to="*.java.bak"/>

<!--filtermapper:Ant1.6.3 Introduced, his mapper implementation will filterchain Apply to Source File Name-->
<filtermapper>
  <replacestring from="\" to="/"/>
</filtermapper>
<!--Ant1.7 Introduce, scriptmapper Execution support Apache BSF perhaps JSR 223 Scripts written in the language.-->
<scriptmapper language="javascript">
  self.addMappedName(source.toUpperCase());
  self.addMappedName(source.toLowerCase());
</scriptmapper>
<!--Ant1.8 Introduce, firstmatchmapper Supports any number of mapper,Return the first matching mapper Results.-->
<firstmatchmapper>
  <globmapper from="*.txt" to="*.bak"/>
  <globmapper from="*A.*" to="*B.*"/>
</firstmatchmapper>
<!--cutdirsmapper:Ant1.8.2 Introduce, removing the number of directories configured from the source file name. dirs="1"Remove first layer directory-->
<cutdirsmapper dirs="1"/>

3.3.7, FilterSet set of filters

    The purpose of a FilterSet type is to define a set of file filters. File contents are replaced when moving or copying a file. FileSet types can be defined outside of a target and referenced within it. Of course, they can also be nested directly within a target.

AttributeDescriptionRequired
begintokenDefines a special character that specifies the starting position of the string to be filtered. The default is @, such as @DATE@No
endtokenDefines a special character that specifies the end identifier of the string to be filtered. The default is @, such as @DATE@No
filtersfileSpecify a single filter file (file property specifies file)No
recurseUsed to indicate whether more replacement flags can be found, defaulting to true.No
onmissingfiltersfileIndicates the behavior when specifying a filter file that does not exist. One of the failures, warnings, ignores. Starting with Ant 1.7No

    The FilterSet type can directly contain the Filter type, which defines a specific file filter.

AttributeDescriptionRequired
tokenName of token to replaceNo
valueSpecify an alternate value that can refer to a variableNo

Use cases:

1) Create a new aa.txt text file in the dist directory as follows:

-----Start replacing default mode@Starting position
DATE
@DATE
@DATE@
----------End position
-----Start replacing custom mode%*Starting position
DATE
%DATE
%DATE*
----------End position

  2) Write configuration file copyfilter.xml

<project name="MyProject" default="" basedir=".">
<property name="TODAY" value="20211028" />
<!--Directory copy: will dist Copy directory to dist_copy -->
<copy todir="dist_copy">
  <!--matching dist All under Catalog txt text-->
  <fileset dir="dist">
      <include name="*.txt" />
  </fileset>
  <!--Will find the copied files by default@DATE@Replace the beginning and end characters with the specified value-->
  <filterset>
    <filter token="DATE" value="${TODAY}"/>
  </filterset>
  <!--We can specify that our own identity will find copied files by default%DATE*Replace the beginning and end characters with the specified value-->
  <filterset begintoken="%" endtoken="*">
    <filter token="DATE" value="${TODAY}"/>
  </filterset>
</copy>
</project>

3) Case Execution and Its Effect

 

3.3.8, PatternSet defines a set of schemas

    The PatternSet_type can be viewed as a collection, and the defined PatternSet type can be referenced in the Ant component file through the refid attribute. PatternSet_type can be used in FileSet and DirSet types to define a matching set of files or directories.

AttributeDescriptionRequired
includesUsed to specify the file mode to be included in the PatternSet. This property specifies the pattern of multiple contained files, equivalent to using a list to save the file patternAll files are included.
includesfileUsed to specify specific files to includeSee includes
excludesUsed to specify file patterns that will not be included in the PatternSet. This property acts exactly the opposite of the includes propertyNo files except default excludes are excluded.
excludesfileUsed to specify specific files that are not includedSee excludes

Use cases:

<!--Match so does not include a name of Test Of java Files, you can have more than one include-->
<patternset id="non.test.sources">
  <include name="**/*.java"/>
  <exclude name="**/*Test*"/>
</patternset>

3.3.9, Selectors Selection Elements

    The selector type can be viewed as an element of the FileSet type, which is used internally to filter files. When using the selector type, you can define the selector type outside the target and then reference it through the refid attribute. Different selectors have different attributes, and some selectors can contain additional selectors, which are often considered selector containers.

Core Selectors:

selectorselector description
<contains>Select a file containing a specific text string
<date>Can be used to select files whose modification time is before or after a specific time
<depend>Used to compare two files with the same name under different directories, and then select the targetdir property of the file with the latest modification time: Specify the target file directory for comparison. Granarity property: Allowable error in milliseconds used to specify a file modification time
<depth>Used to specify the depth of the file directory for the selected file
<different>Select files from two directories that are considered different
<filename>Select files that match the specified file matching pattern
<type>Specify whether you want to select a directory or a file
<size>Select files larger or smaller than a specific number of bytes
<readable>Select Readable Files
...20 in official

Use cases:

1) Create three new html files, two containing/one without <script>tags;

2) New: selectrq.xml

<project name="MyProject" default="dist" basedir=".">
   <target name="dist" description="contains use">
      <!--Copy files to-->
      <copy todir="dist_copy">
	      <!--Match file dist/*html-->
	      <fileset dir="dist" includes="*.html">
		    <!--Include in selected file script Label-->
            <contains text="script" casesensitive="no"/>
          </fileset>
	  </copy>
  </target>
</project>

3) Case effect:

3.1.10, ZipFileSet zip format file set

    The ZipFileSet type can be thought of as a special FileSet type. The ability to package zip files is accomplished through the built-in zip task of the Ant tool. ZipFileSet comes in two different forms:

1) When the src attribute in the ZipFileSet is used, the files in the directory src are organized in zip file format.

2) When the dir attribute in the ZipFileSet is used, the files under the directory dir will be organized as a file system.

AttributeDescriptionRequired
prefixThe prefix used to define the path of the file in the ZipFileSet. Files that match this prefix will be packagedNo
fullpathUsed to define the full path of files contained in ZipFileSetNo
srcTo replace the current directory location, this src specifies that files in the directory will be packaged in zip file formatNo
filemodeUsed to define the permission form of a file for use under UNIX or Linux.No; default is 644
dirmodeUsed to define the form of permissions for a directory, used under UNIX or LinuxNo;default is 755
encodingSpecify the character encoding to use for file names in zip filesNo; default JVM character encoding
erroronmissingarchiveSpecify what happens if the archive does not exist. If true, a build error will occur;No; defaults to true,Ant 1.8.0

  Use cases:

1) There are three HTML files and a compressed package examples.zip containing index.html in the dist directory.

2) Write zip.xml

<project name="MyProject" default="dist" basedir=".">
   <target name="dist" description="zip demo">
      <zip destfile="dist/myhtml.zip">
	    <!--with zip Form ( myhtml.zip)Pack dist Directory html File to deploy Catalog-->
	    <zipfileset dir="dist" prefix="deploy" includes="*.html"/>
		<!--And add zip.xml File to deploy Package together under directory-->
	    <zipfileset dir="." includes="zip.xml" fullpath="deploy/zip.xml"/>
		<!--At the same time, zip Form ( com.zip)Pack dist/class/All files in the directory to deploy/src Catalog-->
		<zipfileset src="dist/examples.zip" includes="**/*.html" prefix="src/"/>
	  </zip>
  </target>
</project>

3) Execution of ant commands and case effects

3.1.11, TarFileSet tar format file set

  Since ant1.7, TarFileSet has been a stand-alone type. You can define an id attribute for tarfileset and reference it by refid. Tarfileset is a special-formatted fileset with two different forms:

1) When using src attributes or nested resource collections, tarfileset uses the files found in src as tar entries. (

2) When using the dir attribute, tarfileset uses the file system files found under dir as tar entries.

AttributeDescriptionRequired
prefixThe prefix used to define the path of the file in the TarFileSet. Files that match this prefix will be packagedNo
fullpathUsed to define the full path of the file contained in the TarFileSetNo
srcTo replace the current directory location, this src specifies that the files in the directory will be packaged as tar filesNo
filemodeUsed to define the permission form of a file for use under UNIX or Linux.No; default is 644
dirmodeUsed to define the form of permissions for a directory, used under UNIX or LinuxNo;default is 755
usernameUser name of tar entry, different from UIDNo
groupGroup name of tar entryNo

Use cases:

<!--Download archive file some-archive.tar.bz2,Decompress it dynamically, and it will lib Copy the contents of the directory to some Directory and discard the rest of the archive file-->
<copy todir="some-dir">
 <tarfileset includes="lib/**">
   <bzip2resource>
     <url url="https://example.org/dist/some-archive.tar.bz2"/>
   </bzip2resource>
 </tarfileset>
</copy>

3.4, Some other common usage notes of Ant

3.4.1, available task

AttributeDescriptionRequired
propertyThe name of the property to be set.Yes
valueTo set the value of the property. Defaults to "true". Defaults to trueNo
classnameClass name of class classYes
fileFile Path
resourceThe resource to look for in the JVM.Look at the resources in the JVM.
classpathThe classpath to use when looking upclassname orresource. Used when classname and resource attributes are presentNo
filepathThe path to use when looking up file.Path when there is a file nodeNo
classpathrefThe classpath to use, given as a reference to a path defined elsewhere.classpath because the path defined elsewhere serves as a reference.No
typeThe type of file to look for, either a directory (type="dir") or a file (type="file"). If not set, the property will be set if the name specified in the file attribute exists as either a file or a directory.No
<!--If Specified Not Displayed value,When something is checked, property Default value is true-->
<available  property="Property Name" file | classname | resource = "What is judged to exist" value="Specify a value for property name display"/>

Use cases:  

<project name="MyProject" default="dist" basedir=".">
   <property name="a" value="a"/>
   <property name="b" value="b"/>
   <property name="a,b" value="c"/>
   <!--There if="a,b"One, not two,Matched, printed out a-->
   <target name="dist" description="zip demo" if="a,b">
	  <echo>${a}</echo>
  </target>
</project>

3.4.2, native2ascii Task

<!--Will configure file(*.xml)To.properties file
	ext: File extension used when renaming output file
-->
<native2ascii encoding="GBK" src="config" dest="WEB-INF" includes="*.xml"
			ext=".properties" />

Posted by perrio on Wed, 03 Nov 2021 09:18:05 -0700