ANT learning guide

xiaoxiao2021-03-06  40

Ant Learning Guide Content Summary: Ant is a Java-based automation scripting engine, the script format is XML. In addition to making Java compilation related tasks, Ant can also achieve a number of applications in a plugin. 1) Basic concepts of Ant: 2) Ant installation: Unpack, set path 3) Ant's use: The best learning is just a simple and practical example start ... Ant's basic concept: java Makefile is a code After the project is large, each time I recompile, package, test, etc., it will become very complicated and repeated, so the Make script in the C language will help the batch of these work. Application in Java is a platform-independent. Of course, these batch tasks are not completed with platform-related Make scripts. Ant itself is such a process scripting engine for automated calling programs to complete project compilation, packaging, test, etc. . In addition to Java-based platforms, the format of the script is based on XML, which is better to maintain than the Make script. A series of tasks (Target) is set in each Ant script (default build.xml): For example, there may be the following tasks for a general project. Task 1: Usage Print this script Help information (Default) Task 2: Clean <- Init Clear Initialization Environment Task 3: Javadoc <- Build <- Init Generate Javadoc Task 4: Jar <- Build <- INIT generates JAR task 5: All <- jar javadoc <- build <- in j 完成 完成: JAR Javadoc often contains a certain dependency between multiple tasks: such as putting the entire application packaging task ( This is based on the compilation task, and the compilation task depends on the entire environment initialization task (INIT). Note: I see that the names in the Ant scripts in many projects are basically consistent, such as compilation. BUILD or Compile; package general call JAR or WAR; generate documents generally named javadoc or javadocs; Perform all task all. In each task, Ant will call some external applications according to the configuration and configure the corresponding parameters. Although Ant can call external applications very rich, it is actually 2,3: such as Javac Javadoc Jar et al. When the ANT is installed, add the path to the bin pointing to Ant in the system executable path. For example, you can add the following configuration on / etc / profile on GNU / Linux: Export Ant_Home = / Home / Ant Export Java_Home = /usr/java/j2sdk1.4.1 export path = $ PATH: $ java_home / bin: $ ant_home / bin After this is executed, if you do not specify the configuration file Ant will save the build.xml this configuration file, and execute according to the configuration file Tasks, the default task settings can point to the most common task, such as: build, or pointing to print help: usage, telling users that there are those script options that can be used.

The best learning process of Ant is to understand the build.xml scripts in the Open source project, and then simplify into a simpler, Ant and Apache, a lot of very project items on Ant and Apache, easy to use, and Adaptability is very strong, because the establishment of these projects is often derived from the most direct needs of developers.

The following is an example of a Weblucene application: Modify build.xml from Jdom: < property file = "$ {basedir} /build.properties" /> <

Property name = "lib.dir" value = "./ src / web-inf / lib" /> < Property Name = "build.src" value = "./ src / web-inf / build" />

================================= generates the $ {name} .jar file" />

=== -> = "Build" depends = "prepare-src">

DESTDIR = "$ {build.dest}" debug = "$ {debug}" Optimize = "$ {Optimize}>

============================================================================================================================================================================================================= ==== -> < DELETE> Tasks: USAGE prints help documents, tells those task options: available Build, Jar, Javadoc and Clean. Initializing Environment Variables: INIT All tasks are completed based on some basic environment variables, which is the basis of follow-up other tasks, During the environmental initialization, 2 points can be convenient: 1 In addition to using the default Property sets the Java source path and output path, the settings in the external build.properties file are referenced This can be easier to understand the build.properties, after all, XML is more readable than the property file of Key Value. It is also convenient to use Build.properties. Other users are liberated from the details. 2 ClassPath Settings: Used: is equivalent to setting: classpath = / path / to / resin / lib / jsdk23.jar; / path / to / Project / lib / *. jar; file replication: pre previous-src creates a temporary src storage directory and output directory.

Compilation Task: Build compile ClassPath Environment Find a reference to a PATH object package task: JAR written by Package Generation Project ". Jar"! - ================================================================================================================================================================== =================== -> <

! - create the class package -> Generate Javadoc document task: javadoc

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

New Post(0)