Ant-build.xml compiling file

Source: Internet
Author: User

Ant development ant build file when you start a new project, you should first write the ant build file. The build file defines the build process and is used by everyone in the team development. The ant build file is named Build.xml by default and can be used for other names. Just pass the name as a parameter to ant at run time. The build file can be placed in any location. The general practice is to put it in the top-level directory of the project, This will keep the project concise and clear. The following is a typical project hierarchy.
(1) src deposit file.
(2) class holds the compiled file.
(3) Lib holds third-party jar packages.
(4) Dist Storage package, post code.
The ant build file is an XML file. Each build file defines a unique project (project Element). You can define many goals (target elements) under each project, and there can be dependencies between those goals. When such targets are executed, The goals they depend on need to be executed. Multiple tasks can be defined in each target, and the task sequence to be executed is also defined in the target. Ant must invoke the defined task when it builds the target. The task defines the command that ant actually executes. The tasks in ant can be 3 classes.
(1) Core tasks. The core task is Ant's own task.
(2) Optional tasks. Can be selected and pragmatic from a third-party task, so an additional jar file is required.
(3) User-defined tasks. User-defined tasks real users develop their own tasks.

1.<project> Label
The root tag of the build file for each build file corresponding to a project .<project> tag. It can have multiple intrinsic properties, as shown in the code, with the meanings of each of its properties as follows.
(1) default indicates the run target, and this property is required.
(2) Basedir represents the base directory of the project.
(3) name indicates the project name.
(4) Description represents the description of the project.
Each build file corresponds to a project, but a large project often contains a large number of sub-projects, each of which can have its own build file.

2.<target> Label
You can have one or more target tags under a project tab. A target tag can depend on other target tags. For example, there is a target for compiling the program, and another target for claiming the executable. You must compile the file before you build the executable file. The target of the executable file depends on the target of the compiler. All properties of target are as follows.
(1) name indicates that this attribute is required.
(2) depends indicates the target of dependence.
(3) If indicates that the property is set only when it is executed.
(4) unless indicates that the property does not execute when it is not set.
(5) Description represents the description of the project.
The ant's Depends property specifies the order in which target is executed. Ant executes each target sequentially, in the order in which the target appears in the depends attribute. Before executing, First, you need to execute the target that it depends on. The depends property of target named run in the program is compile, and the depends property of target named Compile is prepare, So the order of the target execution is prepare->compile->run. A target can only be executed once, even if there are multiple target dependent on it. If there is no if or unless attribute, target is always executed.

3.<mkdir> Label
This tag is used to create a directory, which has a property dir is used to specify the name of the directory created, the code is as follows: <mkdir dir= "${class.root}"/> created a directory with the above code, which has been specified by the previous property tag .

4.<jar> Label
This tag is used to generate a jar file with the following properties.
(1) DestFile represents the jar file name.
(2) basedir indicates the file name being archived.
(3) includes indicates that the file mode is not archived.
(4) exchudes indicates the excluded file mode.

5. <javac> tags
This tag is used to compile one or a set of Java files with the following properties:
(1). Srcdir represents the directory of the source program.
(2). Destdir represents the output directory of the class file.
(3). Include indicates the mode of the compiled file.
(4). Excludes indicates the mode of the excluded files.
(5). Classpath represents the classpath used.
(6). Debug represents the debug information contained.
(7). Optimize indicates whether optimization is used.
(8). Verbose indicates that detailed output information is provided.
(9). Fileonerror means that it stops automatically when it encounters an error.

6. <java> tags
The tag is used to perform a compile-generated. class file with the following properties.
(1). classname represents the class name that will be executed.
(2). jar represents the jar file name that contains the class.
(3). The classpath used by the. Classpath.
(4). Fork indicates that the class is running in a new virtual machine.
(5). FailOnError indicates that it stops automatically when an error occurs.
(6). Output indicates the export file.
(7). Append indicates that the default file is appended or overwritten.

7.<delete> Label
This tag is used to delete a file or a set of files, go to properties as follows:
(1). File indicates the files to be deleted.
(2). Dir indicates the directory to be deleted.
(3). Includeemptydirs Indicates whether you want to delete the empty directory, and the default value is delete.
(4). FailOnError Indicates whether the default value is stopped automatically when an error is encountered.
(5). Verbose indicates whether the deleted file is listed, and the default value is not listed.

8.<copy> Label
This tag is used for a copy of a file or set of files with the following properties.
(1). file represents the source file.
(2). ToFile represents the target file.
(3). Todir represents the target directory.
(4). Overwrite indicates whether the destination file is overwritten, and the default value is no overwrite.
(5). Includeemptydirs indicates whether to copy an empty directory, and the default value is copy.
(6). FailOnError indicates that the default value is stop if the target is not found to stop automatically.
(7). Verbose Indicates whether detailed information is displayed and the default value is not displayed.

Ant's Data type
In a build file, you often need to use data types in order to identify files or filegroups. The data type is contained in the
Org.apache.tool.ant.types package. The following is a brief description of some common data types in the build file.

1. Argument type
Programs that are called by the ant build file can pass command-line arguments to them through the <arg> element, such as apply,exec and Java tasks, which can accept nested <arg> elements and specify parameters for their own procedure calls. The following are <arg> All of the properties.
(1). Values is a command parameter. This property is used if the parameter type has a space but wants to use it as a single value.
(2). file represents the file name of a parameter. In the build file, this file name is relative to the current working directory.
(3). Line denotes multiple parameter lists separated by spaces.
(4). path represents the path.

2.ervironment type
External commands or programs called by the ant build file the,<env> element has developed which environment variables to pass to the executing system command,<env> element can accept the following properties.
(1). File indicates that the environment variable is worth the file name. This file name is converted to an absolute path.
(2). path represents the path to the environment variable. Ant will convert it to a local convention.
(3). value represents a direct variable of an environment variable.
(4). Key indicates the name of the environment variable.
Note that file path or value can only take one.

3.filelist type filelist is a data type that supports named file lists, and files contained in a filelist type are not necessarily files that exist. The following are all of its properties.
(1). Dir is the directory used to calculate the absolute file name.
(2). Files is a comma-delimited list of file names.
(3). refID is a reference to a <filelist> that is defined somewhere.
Note that Dir and files are necessary unless REFID is specified (in this case, dir and files are not allowed).

4.fileset type
The Fileset data type defines a set of files and is typically represented as a <fileset> element. However, many ant tasks are built as implicit fileset, which means they support all fileset attributes and nested elements. The following is a list of properties for Fileset.
(1). dir represents the base directory for Fileset.
(2). If the value of CaseSensitive is False, Fileset is not case-sensitive when matching the file name, and its default value is true.
(3). Defaultexcludes is used to determine whether to use the default exclusion mode, which is true by default.
(4). Excludes is a comma-delimited list of file patterns that need to be dispatched.
(5). Excludesfile indicates the file name of each row that contains one exclusion mode.
(6). Includes is a comma-delimited list of file patterns that need to be included.
(7). Includesfile indicates that each row includes a file name that contains a pattern.

5.patternset type
Fileset is a grouping of files, while Patternset is a grouping of patterns, they are closely related concepts .<patternset> support 4 properties: Includes Excludex includexfile and Excludesfile, same as Fileset. Patternset also allows the following nested elements: Include,exclude,includefile and Excludesfile.

6.filterset type
Filterset defines a set of filters that will replace the text of a file when the file is moved or copied.
The main attributes are as follows:
(1). Begintoken represents the token that the nested filter searches for, which is the string that identifies its start.
(2). Endtoken represents a token that is searched by a nested filter This is the string that identifies its end.
(3). ID is the unique identifier of the filter.
(4). refID is a reference to a filter defined somewhere in the build file.

7.Path type
The path element is used to represent a classpath, but it can also be used to represent other paths. When using Zuoyi attributes, the items in the path are separated by semicolons or colons. At the time of construction, this delimiter will replace all the path separators in the current platform with the following properties.
(1). location represents a file or directory. Ant expands this to an absolute path internally.
(2). refID is a reference to a path defined somewhere in the current build file.
(3). path represents a list of files or path names.

8.mapper type
The mapper type defines the relationship between a set of input files and a set of output files, with the following properties.
(1). classname represents the class name that implements the Mapper class. Used to create a custom mapper when the built-in mapper does not meet the requirements.
(2). classpath represents the type path used when looking for a custom mapper.
(3). Classpathref is a reference to a class path defined somewhere.
(4). The meaning of the From property depends on the mapper used.
(5). The meaning of the to property depends on the mapper used.
(6). The value of the Type property is one of the Identity,flatten glob merge RegExp, which defines the type of built-in mapper to use.

Ant's Run
After installing Ant and Configuring the path, switch to the directory in the build file on the command line and enter the ant command to run ant. If no parameters are specified, ant queries the Build.xml file in the current directory. If you find it, use the file as the build file. If you have a –find option, Ant will find the build file in the parent directory until it reaches the file system with the directory. If the name of the build file is not build.xml, then ant can use –buildfile file when it runs, where file specifies the name of the build file to use, as shown in the following example:
Ant shows that the build file that represents the current directory is the default target for Build.xml to run Ant.
Ant–buildfile Test.xml run ant with the Test.xml file in the current directory, execute the default target

Ant-build.xml compilation file in a detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.