Use ANT integration reading 2842 source (indicate) WANGCHQ
[中文 JAVA Technology Network 2003-07-22]
Manage your code, DOC file, compile, configure, etc. Are you doing: You manage your source directory, compile file, copy, implement ... Write BAT in Window, write shell in UNIX? Unfortunately, I don't write it. So I make an EJB process is this: write code -> write a BAT compile code -> Organizational file (EJB-JAR.XML, JBOSS.XML ...) -> Compressed file generation JAR document -> Implementation .. .... (as well as the same test process) (do not need jbuild?) Every time you modified this time, you have to repeat countless times, the PASTE ... process, so tired, take time. But I really don't want to go to school, I have to learn, so 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 it. Basic usage, I hope you can master it through my articles and trials for half a day. Content: Download, Install Hello Anthello Ant Promotion Reference and Download Download, Installation Download? Is it a big pile of parameter variables?: (Http://jakarta.apache.org/ant/index.html It is apache Java Project "Jakarta" subproject. You can choose the current version, I am currently 1.5, WINDOW version, the following uses 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. That is. Hearo Ant We have to develop a Java class: its content is only one sentence, output "Hello Ant" string. And use Ant completes compilation and running, this example is just to run Ant, not with extra things. The following picture is a document organization, please establish a corresponding directory, and write Helloant.java, follow the documents of people, and also move.
Hello.hem Helloant; 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 profile build.xmlbuild.xml XML version = "1.0" encoding = "gb2312"?>
DOS Enter the directory of Hello-Ant, the directory where build.xml is located, we must use the Ant tool to execute it, execute:% ant_home% / bin / ant -file build.xml with the ANT tool to execute the configuration file in the current directory Build .XML or: ANT -FILE BUILD.XML If you set% Ant_Home% / bin to Path this time this time this time, this is the answer: command prompt window D: / temp / hello-ant> ant -file build.xmlbuildfile: Build.xmlmain: [Javac] Compiling 1 Source File to D: / Temp / Hello-Ant / Build / Classes [Java] Hello Ant, Ant's first contact, great! BUILD SUCCESSFULTITAAL TIME: 2 Secondsd: / Temp / Hello-Ant> Check the build / classes directory, oh, see the compiled file is here: build / classes / hello / ant | This paragraph is more nonsense, you may say: This simple work writes a batch of batch, and XML and Ant, put my time is wasted, I used JBuild or WebShpere. What did you understand? 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 bit, but save you formerly spending a crushing copy, time on the Paste. And I found the quality of management code. We must Improve the build.xml, let it do more: Define global variable initialization, mainly establishing a directory compilation (already) packaged for JAR Establishing API Documentation Generation Distribution Product Everything pays attention to balance, you want Ant to do more Of course, I have to be tired, but only take it once, the construction of the future code modification is "one button" completed, we make a simple example of Hello, you can do J2EE exercises. We want to expand the directory structure, making it more like an east: Ant processing catalog: Ant processing Directory: Figure: / src, / docs, / lib is the file structure of its organization, / build, / dist ANT dynamically generated finished product.
/ 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.halloant / DOCS Handwritten Description Document / LIB program The JAR, such as J2EE.jar, Mail, Jar ... / Build uses Ant dynamically generated build directory / build / classes compiled class file / BUILD / DOCS COPY "/ DOCS" handwriting documentation, and ANT generated API document / build / lib places our own Helloant.class package finished 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, you should also need JAR" / lib "program, here we No.
The above is the document organization I have learned. You can organize us to write the necessary documents in accordance with your hobby: Hello.ant. Helloant.java has /src/script.bat@echo offecho ========== ======================================================= c 请Environmentecho .echo java_home:% java_home% echo ========================================= =============% java_home% / bin / java -classpath ../lib/hello-ant.jar Hello.Helloantpause / DOCS / INDEX.HTML John a handwritten document Hello ANT Software Project Manual DOCS ------------------------------------------------------------------------------------------------------------------------ ----------------------------------- Access API document /BUILD.XML configuration file XML Version = " 1.0 "Encoding =" GB2312 "?>
======================================== Document structure is:
-> ================== -> ====================================================================================================================== ==> = "javadocs" depends = "jars" description = "-> creates the API Documentation"> =========== -> http://jakarta.apache.org/ant/manual/using User's Description http://jakarta.apache.org/ant/manual/coretasklist.html core tasks Other big stacks You have to watch. But I think it is a waste of time. http://jakarta.apache.org/ant/manual/index.html manual indexhuihoo.com translation adaptation of ant / manual / usinghttp: //www.huihoo.com/java/ant.html with ANT configuration of Application: Yubin Bin http://develop/article?columnid=295&articleid=27619&pageno=1ibm utilizes Ant and Junit to increase development - using unit tests to gradually improve the code http://www-900.ibm. Com / developerWorks / CN / Java / J-Ant / INDEX.SHTML