Ant learning notes

xiaoxiao2021-03-06  44

Ant learning notes

Ant is a subproject of the Apache project group, is a Java-based automation scripting engine, and the script format is XML. In addition to making Java compilation related tasks, Ant can also achieve a number of applications in a plugin.

General learning ideas:

Ant's basic knowledge and concept Ant's installation, unpacking, setting, and simplicity using Ant's simple application and operation below.

Some basic knowledge and concepts of Ant

When the scale of project development is getting bigger, it is more and more heavy, and some operations such as recompilation, packaging, testing, deployment each time, have become very complicated and repeated. The applications in Java are not related to the platform. If these operations are implemented with integrated IDE programming development tools, although it is easy to save, it is actually applied, but it is still necessary to handle these complex and repetitive work like Ant. . Ant itself is such a process education engine, used for automated calling programs to complete project compilation, packaging, testing, deployment and other operations. In addition to Java-based platforms, the format of the script is based on XML, easy to write and modify, but also related to the platform. Some tasks have been set in each Ant script (generally build.xml file). These tasks are not disorderly, and there is a certain dependency between them, and they have the order of success. For example, in Java's taught people: init, compile, javadoc, jar, deploy, clean, etc. (of course the name of the task here, you can be free, as long as you know what it wants to do Operation and their dependencies), these tasks as the name suggests, see what they have to do.

INIT is to perform initialization operation, that is to say to perform the initial operation of this environment and the required resources before performing compilation, packaging, etc. Compile is used to compile the Java class, generate .class file Javadoc is used to generate an API document JAR is used to package the Class file package generated. JAR file deploy is the clenant used to perform deployment operations is to perform some clearance Operation. Can

As you can see here, there is a certain dependency between them. The Compile, Javadoc, JAR here must rely on the completion of the initialization operation, and deploy has to rely on Compile, Jar and other operations. This way you can see that there is a certain relationship between them. ANT is to organize and perform one another operation based on the interrelationship between these tasks. The script in Ant is generally done with an XML file (usually build.xml), clearing the relationship between tasks and tasks, which is clear, easy to overwrite the relationship with XML file hierarchy. The elements that generally need to use are Project, Target These two (this is also the minimum requirement, otherwise it is also called Ant script!

), Project is as a root element, which is generally defined in attributes such as project names and directories to perform operations. Target is one after another task, you can define multiple. The following will be used to describe the writing rules for the ANT script.

Ant installation, unpacking, setting, and use

Ant installation can be downloaded from Apache's website: http: //ant.apache.org, the latest version is ANT1.6.2. It is generally unpacking in compressed format file Ant, usually you can separate it separately into an ANT_HOME directory. Use the WinRAR or WinZip tool to extract the settings of Ant, (Default Your Machine has installed JDK, and sets Java_Home and other pure Java settings) This requires how to configure it according to different operating systems, I am here. Only the Windows system is used to set, and the settings of other systems can be queried to the official website of Apache Ant. It is generally decompressed to set in the environment variable of Windows. This requires setting Ant_home in Path, sets its Ant.jar packet path in ClassPath, and needs to set an ANT_HOME environment variable. I will illustrate Windows 2000. I will download the Ant_1.6.2.zip after D: / Pan root directory to get ant_home, which is D: /nt_1.6.2; "My Computer" in Windows 2000, right click, take its environment Variables, for settings, you have to find Path in its environment variable, add D: /nt_1.6.2/bin directory, in this entry, add D: /nt1.6.2/lib directory, To create a new ANT_HOME environment variable, set its value D: /nt_1.6.2. This will open the DOS tool, you come to Ant, huh, huh! Ant's use, this usually needs to write a build.xml file in the root of your project, as an Ant execution, so the entire project can perform compilation, packaging, testing, deployment, etc. through your script. And repeated work. Simple application and operation of Ant

I will give an example here to briefly introduce the use of Ant's use and script, I hope to have an enlightenment to everyone. Generally use Ant to write an Ant script, then use the ANT command to perform this script, so all tasks defined in the script are all executed. Generally Build.xml is placed in the root directory of the project, so you can perform a comprehensive operation from here. The structure of the rosaround here is this: Source Procedure (Pure Java File) Put in the src directory, the JAR package required for the project is placed in the lib directory, but Build.xml is the file to be written. The root directory. Then we will write a build.xml file and create a script for Ant.

Build.xml <

/ target> above The script is very simple, and practical. Here I define a few tasks, that is, the few tasks I have just said: init, compile, javadoc, jar .usage is used to display the task instructions and task lists you write. DIST is deploy, here is just the name is different. Not will be described here, the same as the above.

In the definition of the project (Electone Project) has a default property, it is used as the default task of this project, that is, you need to specify a default task to perform, so Ant can at least perform a task. This is also specified in Ant. This default task, you can specify one at will, but to set according to your needs, you can generate something you want, you can generate something you want every time Ant.

They can be seen by identifying Depends in each task, such as: Compile To rely on init, then you need to add the depends attribute in the task property definition of Compile, and specify it dependent on INIT, other tasks dependence is similar to this, not described. Some of the other properties can be obtained from Ant's guidelines, which is not told here.

Reference:

Carda's introduction to Ant: http://www.chedong.com/tech/ant.html Ant Official Website: http://ant.apache.org/ Ant1.6.2 User Manual (English): http: // Ant.apache.org/manual/index.html

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

New Post(0)