Ant use

xiaoxiao2021-03-05  22

First, what is Ant Management Your code, DOC file, compile, configuration, etc. How do you do: Your management source directory, compile file, copy, implement ... Write BAT in Window, Write shell in UNIX? If you don't write, simple production of an EJB is like this: write code -> write a BAT compile code -> Organizational file (EJB-JAR.XML, JBOSS.XML ...) -> Compressed file generation JAR Documentation -> Implementation ... (as well as the same test process) (do not use jbuild?)

Every time this is modified, it has to be repeated countless times, and the Paste ... process is taken, and the efficiency is not high.

If you want to automate a predefined action but don't want to be too tired, then, I think Ant tools are good: it can be used in different platforms (cross-platform) with the same usage. It is Java made, free, open source, is said to have become a truthful Java build standard, and I have heard that the master is used ... ^ _ ^

Second, download Ant http://jakarta.apache.org

Third, decompression, set the environment variable 1. Since it is necessary to use it to run hibernate, you will be able to decompress C: /DEV/apache-ant-1.6.2 2.win r | cmd 3. (Set the environment variable) Type: set Java_home = JDK Path SET ANT_HOME = C: /Dev/apache-ant-1.6.2 set classpath =.;% Java_home% / lib / Tools.jar;% Ant_Home% / lib / ant.jar set path =% PATH%; % Java_home% / bin;% ant_home% / bin or can be in the console system | Advanced | Environment Variables | System Environment Variables, increasing the following two parameters:

Java_Home: C: /J2SDK1.4.1_01 Ant_Home: C: /Apache-ant-1.5.2 Path: Plus after the original path parameter;% java_home% / bin;% ant_home% / bin four, test 1. follow this The directory structure of the file is located and the test code. The current file structure is as follows: Hello-Ant Build Classes SRC Main Hello Ant Helloant.java (content yourself, HelloWorld is ok) build. XML 2. Slices to $ HOME / HELLO-AT in the command line, then type Ant, Enter. 3. The result is as follows: command prompt window F: / helilo-ant> ant buildfile: build.xml

Main: [Javac] Compiling 1 Source File to D: / Temp / Hello-Ant / Build / Classes [Java] Hello Ant, Ant's first contact!

BUILD SUCCESSFUL TOTAL TIME: 2 SECONDS D: / TEMP / HELLO-ANT> Five, ant step 1. We must improve build.xml, let it do more things:

* Define global variables * initialization, mainly to establish a directory * Compiling (existing) * Package to jar * Establish an API Documentation * Generate Distribution Products 2. Expand Hello-Ant Build Classes DOCS LIB DIST BIN DOCS LIB DOCS LIB SRC SCRIPT Main Hello Ant Helloant.java Build.xml

Description / SRC Source File: Java Source, Script Source, JSP Source, XML Configuration ..... / src / main java source

/ src / script window, unix, Liunx execution Script, our simple only one: run.bat: java hello.ant.Helloant

/ DOCS handwriting document

The jar of the class library required for / lib program, such as J2EE.jar, Mail, Jar ...

/ build build directory with ANT dynamic build

/ build / classes compiled class files

/ build / docs copy "/ docs" handwriting documentation, and ANT generated API documentation

/ build / lib places our own Helloant.class package finished Hello-ant.jar

/ DIST / BIN COPY "/ src / script" to execute file

/ dist / DOCS COPY "/ build / docs" documentation

/ DIST / LIB In addition to the Hello-Ant.jar under Copy "/ Build / Lib, we should also need JAR" / lib "program, here we don't.

3. Write /src/script.bat @echo off echo ===================================== =================== Echo Please set Environment Echo. Echo java_home:% java_home% echo ================= =====================================% java_home% / bin / java -classpath ../lib / /HELLO-ANT.jar Hello.ant.Helloant

Pause 4./docs/index.html Write a handwritten document

5./build.xml configuration file

BUILD.XML of Jakarta-Ant-1.6alpha in Ant

Copyright (c) 2002 The Neusoft Software Foundation. All Rights Reserved.

============================================================================================================================================================================================================= ===================== -> Global variable definition ...

Task group (tasks) a Javac task ... A other task

...

Project represents a project, default: Run to the Target (Task Group) Basedir: Benchmark path to the name "Dist". -> can be used in this future: now: b == "Hello / B" == ============================================================================================================================================================================================================= =============== ->

< Property name = "build.lib" value = "$ {build.dir} / lib" />

->

Hello Ant Docs API ]> $ {app .copyright} ]>

- COPY LIB File ->

6. About Build.xml A build.xml contains a complete XML description of an automation process of an engineering, and is basically consisting of three stoodies:

1. Definition of global variable

2. Task Force 3. Many single tasks ... Like Copy, Delete, Javaac, Jar ...

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

New Post(0)