ANT Usage Guide (1) Manage your code, DOC file, compile, configure, etc. Are you doing: You manage the source directory, compile file, copy, implementation ...
Write BAT in Window, write shell in UNIX?
Unfortunately, I don't write it. So the process I made an EJB is this:
Write code -> Write a BAT Compile Code -> Organizational File (EJB-JAR.XML, JBOSS.XML ...) -> Compressed file generation jar document ->
Implement ... (as well as the same test process) (not only jbuild?)
Every time this is a repeated countless time, it is tired, so tired. But I really don't want to learn script, UNIX, I have to learn, too tired.
If you want to automate a predefined action like me, don't want to be too tired, then, I think the Ant tool is 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 ... ^ _ ^
I spent 2 days to master its basic usage, I hope you can master it through my articles and trials for half a day.
content:
Download, install Hello Ant Hello ANT Reference and Download
Download, installation and download? Is there a lot of parameter variables? :( http://jakarta.apache.org/ant/index.html It is a child project of Apache's Java sub-project "Jakarta". You can choose current Version, I am currently 1.5, WINDOW version, and here will use it.
After decompression, Ant_home is used to facilitate access. And make sure you also set up Java_home. SET ANT_HOME = D: /java/kit/ant/jakarta-ant-1.5.1 This is my directory. Hello Ant
We have to develop a Java class: its content has only one sentence, output "Hello Ant" string. And use ANT to complete compilation and running, this example is just to run Ant, no extra thing.
The picture below shows the document organization, establish a corresponding directory and write helloant.java
According to the organizational rules of the foreigners, I also move.
Hello.halloant.java package hello.java package hello.java package
Public class helloant {
Public static void main (String [] args) {
System.out.println ("Hello Ant, Ant's first contact, great!");
}
}
Write 1 file in the project root directory (Hello-Ant /): ANT execution configuration file build.xml
Build.xml XML Version = "1.0" encoding = "GB2312"?>
claspath>
java>
target>
provject>
OK, everything is big, oh, no, haven't run it yet.
DOS enters the directory of Hello-Ant, that is, the directory where the build.xml is located, we have to perform it with the ANT tool.
Execute:% Ant_Home% / BIN / ANT -FILE BUILD.XML Use ANT Tool to execute the configuration file in the current directory build.xml
Or: Ant -file build.xml you if you set% ant_home% / bin into the PATH
This time is OK, this is the answer:
Command prompt window D: / temp / hello-ant> ant -file bot.xml buildfile: build.xml main: [javac] compiling 1 source file to d: / temp / hello-ant / build / classes [java] Hello Ant, Ant's first contact, great! Build Successful Total Time: 2 Seconds D: / Temp / Hello-Ant>
Check the build / classes directory, oh, see the compiled file is here: Build / Classes / Hello / Ant / Helloant.class.
Hello Ant
(This is more nonsense, you can be slightly) You may say: This simple work writes a batch of batch, and XML and Ant, put my time is exhausted, I use jbuild or WebShpere. How do you tell you? Anyway, most of the online open source projects use Ant, you can't give people * .jpx, and this tool is too expensive, you can't stand it (of course, the brothers who use D are not afraid ^ _ ^), and Ant can make you clear management And automate all things: compile - implementation - test ..., hey, slightly trouble a little, but save you formerly spending a crushing copy, time on Paste. And I found that the quality of management code has improved.
We have to improve build.xml, let it do more things:
Define global variable initialization, mainly to establish a directory compilation (already) packaged for JAR to establish an API Documentation Generate Distribution Product
Everything pays attention to balance, you want Ant to do more things, of course, you have to be tired, but just use it once, the construction after the change in code is "one button", we make a simple example of Hello You can do J2EE exercises yourself.
We want to expand the directory structure, making it more vomeeration:
Ant processing before compiling:
Directory after Ant processing:
In the figure: / src, / docs, / lib are the file structure, / build, //t is a product generated by ANT.
/ 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 documentation / lib program JAR, such as J2EE.jar, Mail, Jar ...
/ Build uses ANT dynamically generated build directory / build / classes compiled class file / build / docs copy "/ docs" handwriting document, and ANT generated API document / build / lib places our own Helloant.class package finished product Hello-Ant.jar
/ DIST / BIN COPY "/ src / script" Document / Dist / DOCS COPY "/ Build / DOCS" document / DIST / LIB In addition to Hello-Ant.jar under Copy "/ Build / Lib, The program of the copy "/ lib" requires JAR, here we have not.
The above is the document organization I am learning old, everyone can organize according to their hobbies.
We write the necessary documents:
Hello.ant. Helloant.java has
/src/script.bat @echo off
Echo ================================================== =======
Echo Please set Environment first
echo.
Echo java_home:% java_home%
Echo ================================================== =====
% java_home% / bin / java -classpath ../lib/hello-ant.jar hello.ant.helloant
PAUSE
/DOCS/index.html Write a handwritten document Hello Ant Software Project Manual DOCS
Access API documentation
/BUILD.XML configuration file XML Version = "1.0" encoding = "GB2312"?>
============================================================================================================================================================================================================= ===================== Hello-Ant project, learn the 2nd Build file of the ANT tool.
BUILD.XML of Jakarta-Ant-1.6alpha in Ant
Copyright (c) 2002 The Neusoft Software Foundation. All Rights
RESERVED.
============================================================================================================================================================================================================= =====================
->
The document structure is:
...
target>
...
target>
provject>
Project represents a project,
Default: Target (task group) running to the name "dist"
Basedir: Benchmark path.
->
You can use it in the future:
Now: b == "Hello / B"
============================================================================================================================================================================================================= ==================
->
"DOCS directory" - app ->
Define a set of paths after you can reuse this set of paths, for example:
javac>
->
target>
============================================================================================================================================================================================================= ==================
Build the code (compile tasks, file tasks) ========================================== ===========================
->
javac>
target>
============================================================================================================================================================================================================= ==================
Archive Tasks
Create The Project Jars: xxx1.jar and xxx2.jar
============================================================================================================================================================================================================= ==================
->
target>
============================================================================================================================================================================================================= ================== Creates the API Documentation
============================================================================================================================================================================================================= ==================
->
Depends = "jars" Description = "-> Creates the API Documentation> copy> SourcePath = "$ {src.main}" DEFAULTEXCLUDES = "YES" destdir = "$ {build.docs.api}" Author = "True" Version = "True" Use = "true" Windowtitle = "DOCS API"> javadoc> target>
============================================================================================================================================================================================================= ================= Create the distribution That Can Run (Archive Tasks) Mainly from the Copy's COPY from each directory ============================================================================================================================================================================================================= ================== -> copy> copy> copy> target>
============================================================================================================================================================================================================= ================== Cleans Everything (File Tasks) For example, you can delete files in build, leave it to you. ============================================================================================================================================================================================================= ================== -> provject> Build.xml is more, but it is actually very simple: (Comment is more detailed, here can refer to it, then simply say) A build.xml contains a complete XML description of an automation process of an engineering, and is basically consisting of three state: 2. Task Force provject> Other information Java's Build Tool - And App Guide - CCID NET -