ANT-Another Neat Tool-Application Guide

xiaoxiao2021-03-05  27

Compilation source code

The default behavior of Ant's Javac task is to call the standard compiler of any JVM running Ant itself. However, sometimes you may want to call the compiler separately - For example, when you want to specify certain memory options for the compiler, or when you need to use a different level compiler. To achieve this, simply set the Javac's fork property to True, such as the following:

If you want to specify a different Javac executable and pass a maximum memory setting to it, you can do this below:

You can even configure Ant to use a different compiler. Supported compilers include open source JIKES compilers and GCI compilers from GNU Compiler Sets (GNU Compiler Collection, GCC)

2. Create a JAR file

Construction list file

3. Generate timestamp

This needs is solved by simple but very useful TSTAMP tasks. This task is usually called at the beginning of a certain generation process, such as in an init target. This task does not require attributes, and only is enough in many cases.

TSTAMP setting properties:

Attribute Description Example DSTAMP is set to the current date, the default format is set to the current time, the default format is HHMM1603Today set to the current date, with a complete month

2003

year

12

month

In one

day

Name the JAR file package-20031217.jar

You can also configure TSTAMP tasks to set different properties, apply a time offset before or after a current time, or format the string in different ways. All of this is done using a nested Format element, as shown below:

set the offset_time property to 10 minutes from the current time Hours, number of minutes, and seconds.

The characters used to define the format string are the same as those defined by the Java.Text.SIMPLEDATEFORMAT class.

4. Comprehensive

As a few sections provide us with sufficient knowledge required to generate a simple Java project. Here, these code snippets will be combined into a complete generated file, which will compile all the source code in the src directory, put the result class file in the build directory, then package all class files into a JAR file in the dist directory . To test this generated file, you need to include a src directory containing one or more Java source code ----- This directory can contain a large number of simple "Hell World" to a large number of existing projects Anything of the source file. If you need to add JAR files or anything else to Java ClassPath to successfully compile the source code, you only need to add a ClassPath property to it in the Javac task.

The generated file looks as follows:

a Simple java project < Property name = "builddir" location = "build" /> 5. Construction and delete directory

6. Copy and mobile files and directories

Also equivalent to renaming: Move to another: 7. Creating a compressed zip and tar file

Below is an ANT task for creating a zip file:

The same syntax can also be used to create a TAR file. You can also use Gzip and BZIP tasks to compress files. E.g:

Unzip and extract the files is also simple:

It is also possible to include OverWrite properties to control overlay behavior. The default setting is to override all existing files that match the entry in the archive file being extracted. The related task name is Untar, Unjar, Gunzip, and Bunzip.

8. Replace the tag in the file

The Token property specifies the string to look up, and the Value property specifies a new string.

9. Mode match

*, It matches zero or more characters; and? It only matches a character; **, it matches any number of directories.

Example: src * / *. Java will match all Java files in any directory with the SRC prefix;

Mode ** / *. Java will match all Java files under the current directory structure.

10. Use the selector

ANT available list of core selectors:

• Size: This selector is used to select a file according to the byte size of the file (unless you specify a different unit). The attribute is used to set the properties of the comparison (LESS, more or Equal), and the value attribute defines the target size of each file.

• Contains: Only files containing a given text string (specified by the Text property) matches this selector. By default, the lookup operation is sensitive; add CaseSensitive = "no" can change the default settings.

• FILENAME: Name property Specifies the mode of the file name to match. It is essentially the same as the include element, as well as the Exclude element when NEGATE = "YES" is specified. • Present: Select the following file from the current directory structure: They have the same name and relative directory structure as files in the specified targetdir directory.

• Depend: This selector has the same effect as the Present selector, but only the matching file is restricted to the corresponding files relative to the TargetDir location, those files that have been modified recently.

• Date: This selector selects a file based on its last modification date. The property specified by the attribute is Before, after or equal, the datetime property specifies the date and time of comparison with it, this date and time has a given fixed format mm / dd / yyyy hh: mm am_or_pm. Note that there is a built-in 2 second offset on the Windows platform to allow the underlying file system inaccuracies - this may result in matching files exceed expectations. The amount of cyclone allowed can be changed (specified in milliseconds) using the Granularity property.

• DEPTH: This selector checks the number of directory structures of each file. MIN and / or MAX properties are used to select files with the number of desired directory hierarchy.

You can also combine selectors by nesting one or more selectors in a selector container. The most commonly used selector container and only select the files it contains all selectors. Other Select Its containers include OR, NOT, NONE, and MAJORITY.

Below is an example of a file set, which selects only those that are more than 512 bytes and contain strings "Hello".

11. Link the generated file link

There are two ways to generate large projects. One is to make a single generated file to do everything; the other is to call the high-level generated file to call other generated files to perform a specific task, thereby dividing the generation process into many smaller parts.

It is easy to use Ant tasks to call another ANT generation from an ANT generation. In a simple case, you can use the ANTFILE attribute, specify only those generated files to use, and Ant will generate the default target in the generated file. E.g:

Any attribute defined in the parent is defined by default to the child generated file, although this can be avoided by specifying inheritall = "false". It is also possible to pass the explicit attribute by using the Property element - even if INHERITALL is set to false, these properties still apply to the child generation file. This feature is suitable for use in incoming parameters to subconstructive files.

Let us consider an example. Here is a generated file we want to call:

(echo Task - It simply outputs a given message.) Below is the second generation file called the first generation file, it also passes the first generation file to the Message property: Run the output of the second generated file is as follows: buildfile: build.xmlcallsub: showMessage: [echo] message = Hello from Parent Buildbuild SuccessFultotal Time: 0 Seconds12. Use CVS Knowledge Base

An example of an extraction module from the CVS Knowledge Base:

The main attributes of the CVS task are CVSROOT, which is a complete reference to the CVS knowledge base, including connection methods and user details. The format of this parameter is as follows:

[: Method:] [[user] [: password] @] Hostname [: [port]] / path / to / repository

转载请注明原文地址:https://www.9cbs.com/read-35716.html

New Post(0)