Use Ant to make you programs (1)
Summary: Directory Structure Division
There have been countless articles introduced Ant, I will no longer introduce the installation of Ant, configured.
Every friend using Ant has a set of organizations, now I wrote my way.
For your reference, you will be reluctant to forget.
1. Directory structure division
Suppose you have a work directory as: / home / camry / work, here is referred to as Work
In order to adapt to multiple items, I have configured a basic configuration file to put in Work / Common
Next. The directory structure is like this:
Work / Common /
Build_common.xml # This file contains basic build operations
Common.xml # This file is configured for build_common.xml.
It is basically no change.
Build_tomcat.xml # This file contains basic operations with Tomcat cooperation.
Tomcat.xml # This file is configured for build_tomcat.xml.
It is basically only necessary to configure it.
Build.xml # This file is the build configuration that every item is required.
But it is basically no need to change.
Build.properties # This file is configured for build.xml,
Related to specific projects.
USAGE.TXT # This file illustrates the various operations in the build process.
LIB / # This directory is placed some common JAR packages free to repeat.
Checkstyle-all-3.4.jar # is used for code check
HttpUnit.jar # for HTTP unit testing
JUnit.jar # for unit testing
Servlet-Api.jar # is used to write servlet related files
Template / # This directory is a set project template, a project starts
The data of this directory will be copied to the project directory so that
Use directly.
BIN / # This directory places an executable
Build / # This directory is placed the auxiliary file required to build
Checkstyle_checks.xml # This file is the configuration file of Checkstyle
Java.Header # This file is also a checkstyle configuration file.
Used to explain the head structure of your Java file
Dist / # This directory places the target file
Classes / # Class files generated after compiling this
LIB / # JAR file generated after packaging this
LIB / # This directory placement project-related JAR file
SRC / # This directory placement source code
Build.xml # This file is a configuration file for working with CVS.
Main / # This directory is placed in the main source code
Test / # this directory placement test code
All profiles will be described in detail in subsequent articles.
Use Ant to make you programs (2)
Summary: Build_Common.xml, Common.xml and USAGE.txt
2. Introduce Build_Common.xml, Common.xml and USAGE.txt
The following is the contents of the build_common.xml file.
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Copyright 2004 CAMRY.WU@gmail.com
THIS Program Is Free Software; You Can Redistribute It and / or Modifyiit Under The Terms of The GNU General Public License As Published By
The Free Software Foundation; Either Version 2 of the license, OR
ANY LATER VERSION.
This Program is Distributed in the Hope That IT Will Be Useful,
But without Any Warranty; WITHOUT EVEN THE IMPLIED WARRANTY OF
Merchantability or fitness for a particular purpose. See the
GNU General Public License for more details.
You Should Have Received A Copy of The GNU General Public License
Along with this program; if not, Write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
->
Semanticattributes = "true" Keeproot = "false" /> fileset> fileset> path> path> Depends = "Project_init" Description = "Initialize Environment"> target> Srcfile = "$ {path.common} /"} /> target> Depends = "init" description = "prepare build directory"> fileset> copy> target> Classpath = "$ {path.common} /lib/checkstyle-all-3.4.jar" /> File = "$ {path.common} /lib/checkstyle.cache" /> checkstyle> target> DepRecation = "$ {compile.DepRecation}" Destdir = "$ {Dist} / classes" Target = "$ {compile.jdk-version.target}" Source = "$ {compile.jdk-version.source}" Optimize = "$ {compile.optimize}" SRCDIR = "$ {src}"> javac> target> Depends = "Project_clean" Description = "Wipeout All generated files"> target> Depends = "Checkstyle, Compile" Description = "CREATE BINARY Distribution"> delete> JARFILE = "$ {dist.lib} / $ {component.name} - $ {component.version} .jar"> jar> fileset> delete> target> Fork = "false" HALTONFAILURE = "false" failureproperty = "tests.failed" Showoutput = "True"> fileset> batchtest> junit> *********************************************************** ******* *********************************************************** ******* **** One or more tests failed! Check the output ... **** *********************************************************** ******* *********************************************************** ******* lot> target> Depends = "Project_Deploy" Description = "deploy application" /> Depends = "compile" Description = "CREATE Component Javadoc Documentation"> Bottom = "$ {component.title}" Destdir = "$ {DOCS.API}" Source = "$ {compile.jdk-version.source}" DOCTITLE = "$ {component.title}" PackageNames = "*" Access = "protected" SourcePath = "$ {src.main}" Version = "True" WindowTitle = "$ {component.title} (Version $ {Component.Version}"> javadoc> target> Depends = "Project_Fetch" Description = "Fetch Current Source from CVS"> target> Depends = "Checkstyle, Compile" Description = "CREATES SOURCE DISTRIBUTION"> delete> Destfile = "$ {dist.lib} / $ {component.name} - $ {component.version} -src.zip" WHENEMPTY = "fail"> zip> target>
Upload the source file to the server backup, upload the target file to the server release. The contents of this task are set by yourself, usually running the FTP task. -> Depends = "Clean, Jar, Javadoc, Src-Zip" Description = "Publish Project"> target> Build -> Depends = "Clean, Fetch, Test, Jar, Javadoc, Deploy" Description = "build project" /> provject> The following is the content of the common.xml file. Xml Version = "1.0" encoding = "ISO-8859-1"?>
Copyright 2004 CAMRY.WU@gmail.com Common Ant Build Environment ->
Path configuration, basically don't change. But if you use this build tool in a strange environment, Maybe a slightly modify the configuration of these paths. -> build> dist> docs>
src> JDK-VERSION> compile> root> The following is the usage.txt file content. $ {Component.name} build file --------------------------------------------- Available Targets Are: Prepare -> Initialization Project Environment CheckStyle -> Check source file coding specification Compile -> Compilation Jar -> package Build -> Build Test -> Test Clean -> Clear Deploy -> Publish to the web server Publish -> Publish products (source and target files) FETCH -> Get the latest resources from CVS DOCS -> Create an API document All -> Execute Clean, Fetch, Build, Test, DOC, Deploy Main -> Default build process (self-modify) Use Ant to make you a happy program (3) Summary: Build.xml, Build.properties 2. Introduction Build.xml, Build.properties The following is the product of the build.xml file. Xml Version = "1.0" Encoding = "ISO-8859-1"?>
Copyright 2004 CAMRY.WU@gmail.com This Program Is Free Software; You Can Redistribute IT and / or Modify It Under The Terms of The GNU General Public License As Published by The Free Software Foundation; Either Version 2 of the license, OR ANY LATER VERSION. This Program is Distributed in the Hope That IT Will Be Useful, But without Any Warranty; WITHOUT EVEN THE IMPLIED WARRANTY OF Merchantability or fitness for a particular purpose. See the GNU General Public License for more details. You Should Have Received A Copy of The GNU General Public License Along with this program; if not, Write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ->
If the project is going to cooperate with Tomcat, then load Tomcat configuration -> -> target> Depends = "common_prepare" description = "preted build directory"> target> target> Depends = "init" description = "Project-Level Prepare Phase"> target>
If the project is going to cooperate with Tomcat, then call Tomcat's task -> target>
If the project is going to cooperate with Tomcat, then call Tomcat's task -> target> Build Application System -> target> provject> The following is the content of build.properties file. # Initializing the environment # # c 文件 文件 位置, if you want to write this under Windows: D: / Work / Common Path.common = / Home / Camry / Work / Common # Project Related Information Component.name = app Component.package = com.Vitular.app Component.title = app Component.version = 0.1a # CVS root location Cvsroot =: pserver: Camry@x.x.x.x: / usr / cvsroot # ftp setting # ftp.server = x.x.x.x # Remote server location # ftp.user = CAMRY # User name # ftp.pass = ***** # User password # remote.dir = / opt / release # Remote publishing directory location Use Ant to make you programs (4) Summary: Checkstyle_Checks.xml, Java.Header Now there is already a directory structure, there is build_common.xml, common.xml, usage.txt, BUILD.XML, Build.properties, etc., you can already complete most of the tasks. Now you will now describe an auxiliary task, such as code check. The code checks in build_common.xml already has this task, but two configurations are required The file cooperation, you still need to download the Checkstyle's JAR package and will It puts it in a work / common / lib / directory. These two profiles are: work / common / template / build / directory Checkstyle_checks.xml file and java.header file CheckStyle_Checks.xml file Description How should I check on the Java file, The Java.Header file indicates the head structure of each Java file. The checkStyle_checks.xml file is as follows, it is borrowed Johan The source file made a little modification. The specific instructions for each configuration give a link, do not understand You can take a closer look. Xml Version = "1.0" encoding = "ISO-8859-1"?>
Copyright 2004 Johan Kng, http://dev.kanngard.net This Program Is Free Software; You Can Redistribute IT and / or Modify It Under The Terms of The GNU General Public License As Published by The Free Software Foundation; Either Version 2 of the license, OR ANY LATER VERSION. This Program is Distributed in the Hope That IT Will Be Useful, But without Any Warranty; WITHOUT EVEN THE IMPLIED WARRANTY OF Merchantability or fitness for a particular purpose. See the GNU General Public License for more details. You Should Have Received A Copy of The GNU General Public License Along with this program; if not, Write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ->
"- // puppy crawl // DTD Check Configuration 1.2 // en" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
Based on the checkstyle configuration file sun_checks.xml with some minor Modifications .. CHECKSTYLE IS VERY CONFIGURBLE. Be Sure To Read The Documentation AT http://checkstyle.sf.net -> module> "- to have access to ant profmentness. in this case-> Name = "Headerfile" Value = "$ {basedir} /build/java.header" /> module> -> -> module> -> "- Miscellaneous Other Checks. -> module> module> module> The following is my Java file head constructor, of course, each team can have its own agreement. Because the third, 5th, 8 lines change the change of the file, I ignore the inspection of them. This can be seen from the checkstyle_checks.xml file above. / * * ------------------------------------------------- ------------ * file name: _filename_ * Authors: Camry (Camry@gmail.com) * Created: _datetime_ * Copyright: (c) 2003 Vitular Inc. All Rights Reserved. * * Modifications: * * ------------------------------------------------- ---------- * / Some friends may feel that every time I write such a head before the document is not very trouble, but for me, This is very easy to make Vim. When I use Vim to create a Java file, It will automatically add this header, and replace with the appropriate file name and time _filename_ and _Datetime_ These two parameters. How to do this will be explained in the future. There will be such a hassle place when using this CheckStyle: it does not allow excess in the end of the line. Space. For programmers, who cares about several spaces, but the program is very rigorous :) Friends using VIM can find how to easily eliminate row spaces here. Use Ant to make you programs (5) Summary: Build_Tomcat.xml, Tomcat.xml Now introduce how to cooperate with Tomcat. Java's program is largely involved in web, which is still very convenient to use Tomcat when you test. So it is necessary to introduce it. BUILD_TOMCAT.XML under Work / Common / Tomcat.xml is with Tomcat works with the profile of work, it is very simple. The following is the contents of build_tomcat.xml file: Xml Version = "1.0" encoding = "ISO-8859-1"?>
Copyright 2004 CAMRY.WU@gmail.com This Program Is Free Software; You Can Redistribute IT and / or Modify It Under The Terms of The GNU General Public License As Published by The Free Software Foundation; Either Version 2 of the license, OR ANY LATER VERSION. This Program is Distributed in the Hope That IT Will Be Useful, But without Any Warranty; WITHOUT EVEN THE IMPLIED WARRANTY OF Merchantability or fitness for a particular purpose. See the GNU General Public License for more details. You Should Have Received A Copy of The GNU General Public License Along with this program; if not, Write to the Free Software Foundation, inc. -> Semanticattributes = "true" keEProot = "false" /> Depends = "compile" Description = "deploy application"> fileset> copy> fileset> copy> fileset> copy> target> fileset> delete> target> Depends = "jar" description = "Deploy Application As a War File"> fileset> war> fileset> copy> Target> claspath> taskdef> claspath> taskdef> claspath> taskdef> claspath> taskdef> claspath> taskdef> UserName = "$ {tomcat.manager.username}" Password = "$ {Tomcat.Manager.password}" PATH = "/ $ {component.name}" WAR = "$ {component.name} .war" /> target> UserName = "$ {tomcat.manager.username}" Password = "$ {Tomcat.Manager.password}" PATH = "/ $ {component.name}" /> target> UserName = "$ {tomcat.manager.username}" Password = "$ {Tomcat.Manager.password}" PATH = "/ $ {component.name}" /> target> UserName = "$ {tomcat.manager.username}" Password = "$ {Tomcat.Manager.password}" PATH = "/ $ {component.name}" /> target> UserName = "$ {tomcat.manager.username}" Password = "$ {Tomcat.Manager.password}" /> target> provject> The following is the content of Tomcat.xml. Xml Version = "1.0" encoding = "ISO-8859-1"?>
Copyright 2004 CAMRY.WU@gmail.com Ant Build Environment for Tomcat -> tomcat> path> root> When using, pay attention to establish a WAR directory in the WORK / engineering directory / The WAR directory structure is: Work / Engineering Catalog / WAR WEB-INF / Classes / # placed in the class file LIB / # 放 需要 需要 需要 j j Web.xml # web configuration file With these configurations, just start Tomcat, then don't use it when you cooperate with Tomcat. Tubing Tomcat, as long as Ant Deploy, Ant Stop, Ant Start, etc. The task is ok. Use ant to make you enjoy your program (6) Summary: Together with CVS Many people use CVS as version control tools, but it has a little bit of trouble, it is when commit There is no -r option, you can't pass the child directory data. Don't close, you can use Ant to put this gap Buy, just need to do some preparations first. There is a build.xml file in the work / common / template / src / directory, this file It is a CVS task. After the new establishment of a project project, put this build.xml in each subdirectory of the SRC. This file is used to operate the current directory and its subdirectory version control command, which can be recursive. Trouble is to create such files each directory, and the wildcard is not supported when the ANT calls CVS. The name of each file must be written. But this is also more secure. If a friend has a better way, I hope to tell me. . Here is the content of this build.xml file XML Version = "1.0"?> target> target> target> target> target> provject> Use Ant to make you programs (6) Summary: Together with CVS Many people use CVS as version control tools, but it has a little bit of trouble, it is when commit There is no -r option, you can't pass the child directory data. Don't close, you can use Ant to put this gap Buy, just need to do some preparations first. There is a build.xml file in the work / common / template / src / directory, this file It is a CVS task. After the new establishment of a project project, put this build.xml in each subdirectory of the SRC. This file is used to operate the current directory and its subdirectory version control command, which can be recursive. Trouble is to create such files each directory, and the wildcard is not supported when the ANT calls CVS. The name of each file must be written. But this is also more secure. If a friend has a better way, I hope to tell me. . Here is the content of this build.xml file XML Version = "1.0"?> target> target> target> target> target> provject> Use Ant to make you programs (6) Summary: Together with CVS Many people use CVS as version control tools, but it has a little bit of trouble, it is when commit There is no -r option, you can't pass the child directory data. Don't close, you can use Ant to put this gap Buy, just need to do some preparations first. There is a build.xml file in the work / common / template / src / directory, this file It is a CVS task. After the new establishment of a project project, put this build.xml in each subdirectory of the SRC. This file is used to operate the current directory and its subdirectory version control command, which can be recursive. Trouble is to create such files each directory, and the wildcard is not supported when the ANT calls CVS. The name of each file must be written. But this is also more secure. If a friend has a better way, I hope to tell me. . Here is the content of this build.xml file XML Version = "1.0"?> target> target> target> target> target> provject> Use Ant to make you programs (6) Summary: Together with CVS Many people use CVS as version control tools, but it has a little bit of trouble, it is when commit There is no -r option, you can't pass the child directory data. Don't close, you can use Ant to put this gap Buy, just need to do some preparations first. There is a build.xml file in the work / common / template / src / directory, this file It is a CVS task. After the new establishment of a project project, put this build.xml in each subdirectory of the SRC. This file is used to operate the current directory and its subdirectory version control command, which can be recursive. Trouble is to create such files each directory, and the wildcard is not supported when the ANT calls CVS. The name of each file must be written. But this is also more secure. If a friend has a better way, I hope to tell me. . Here is the content of this build.xml file XML Version = "1.0"?> target> target> target> target> target> provject> Use Ant to make you programs (7) Summary: How to use this ANT environment Now there is an entire ANT environment, put it in the work / common / directory, the configuration file is also Completed, you can start working. Steps to conduct projects: 1. Give the project a loud name, just called Proj :) 2. CD to WORK / 3. MKDir Proj 4. Copy Work / Common / Build.xml and Build.properties files to Proj 5. Modify Build.Properties to change the things related to the project, such as what is the name. 6. CD to proj 7. Ant usage (you can see how to use it) 8. Ant Prepare (built the directory structure) 9. Ok, start knocking the code. Create a directory COM / VITULAR / PROJ / 10. Establish a Hello.java file in src / main / com / vitular / proj /. 11. Ant Checkstyle (check if it is qualified) Discover less package.html And not let me create a PUBLIC's constructor. (As long as it contains the main () function it will say this) I have to modify it, and I will check it again. 11. Ant Compile (Compiled) 12. ANT JAR (packaged) ---------------------- 13. ... The rest is not coming.