Ant ---- Construct Application with Ant
Author: This article taken from Yubin Bin: SEOUL October 14, 2002
Introduction to Ant
ANT is Apache to provide a build tool for Java developers, which can be run under Windows OS and UNIX OS, not only open source but also a very easy to use. I strongly recommend installing Javabean, EJB, etc., it is not recommended to set up Make, Makefile, etc., build build tools in shell thinking. Download Ant Official Website: http://jakarta.apache.org/ant/ Download URL: http://jakarta.apache.org/builds/jakarta-ant/release/ Installing Ant Setting ANT_HOME System Variables and Path System Variables · Windows If the ANT installation directory is c: / AT, set the set ant_home = c: / ax set java_home =% PATH%;% ANT_HOME% / bin · UNIX If the ANT installation directory is / USR / local / ANT, set the method below
Export Ant_Home = / usr / local / Ant
Export java_home = / usr / local / jdk1.3
Export Path = $ {Path}: $ {ant_home} / bin
Running Ant, Ant "is a very easy to use tool", because it is very simple to run, as long as you enter "Ant" in the command line, Ant is running. I am using the sequence generator SequenceGenerator, and the build information displayed in the console: View the details. Console snapshot, see the figure below:
Build a first screen of the sequence generator
Build a second screen of the sequence generator
Ant command line parameters
Ant can also pass the command line parameters
-buildfile
It is the target file name you want to use. Ant also has a lot of command line optional parameters as follows: Command line Optional parameters Summary:
Ant [options] [target [target2 [target3] ...]]]]]]]
Options:
-Help Print this Message
-ProjectHelp Print Project Help Information
-version print the version information and exit
-quiet be extra quiet
-verbose be extra verbose
-debug print debugging information
-emacs produpe logging information without adornments
-logfile file use Given File for log output
-logger classname the class thing is to perform logging
-Listener ClassName Add an Instance of Class As a Project Listener
-Buildfile File Use Specified BuildFile
-Find File Search for Buildfile Towards The Root of The FileSystem Anduse The First ONE FOUND
-Dproperty = Value Set Property to Value
Write build.xml
Ant's buildfile is written with XML. Each buildfile contains a Project. Each task element in BuildFile can have an ID property that can be used to reference the specified task with this ID value. This value must be unique. Below are the elements and tasks commonly used in Ant: commonly used elements have "Project", "Target", "Path", "Property", etc. Common tasks have "Ant", "MKDir", "Delete", "Copy", "Javac", "Jar", "Javadoc", "Echo", etc. (Note: Their detailed usage, I am no longer detailed, please refer to the user manual from the Ant when downloading Ant.) I am using the build_for_ejb_templet.xml as an example to explain the elements and tasks commonly used in Ant. Agreement: 1. The front part of each line is "digital" ".", The number represents the line number in the XML file 2. "..." means that there are many code here, not listing the build_for_ejb_templet.xml task division is below the division. Several parts I. Start II. Initialization III. Define ClassPath IV. Prepare v. Compile the EJB section Vi. Compile the web section VII. Compile the J2EE Application Viii. Deploy Application IX. Create the API X. Target for Creating Components BUILD_FOR_EJB_TEMPLET.XML The explanation begins 1.
XML Version = "1.0" encoding = "UTF-8"?>
Explanation: Encoding = "UTF-8" means the XML file uses a UTF-8 encoding format, and if you want to use GBK encoding,
Need to be defined as encodeing = "GBK".
3.
4. Build file for 'componentname'
5. Creation Date: $ DATE: YYYY-M-D $
6. Updated Date: $ DATE: YYYY-M-D $
7. Author: developername
8. Copyright 2002 CompanyName, Inc. All Rights Reserved.
9. ->
Explain: This section is a profile of the file, including file name, creation date, final modification date, author, copyright, created by the author, copyright.
ComponentName Represents file name
YYYY-M-DD indicates the format of the creation date, finally modified the date, such as 2002-5-1
Developername indicates the author of the creation of files
CompanyName Represents Company Name or URL
11. initialization 17. ... 63. Target> Explain: This section is used to initialize all variables 18. Explain: Import the global variables in build.properties in the project root directory, and developers can also redefine global variables in this file. 19. 20. 21. Value = "$ {jboss.home} / server / $ {jboss.configuration} / deploy" /> ... 27. ... 41. 42. 43. Explain: Definitions and JBoss Application Server variables, including lib directory, client directory, The deploy directory and some variables you want to use by J2EE Application deployment. 22. Explain: Define the name of the component 23. Explain: Define the source code directory path 24. Explain: Define the resource directory path 25. Explain: Define the library directory path 26. 28. Explain: Define the primary directory path for source code 29. Explanation: Define the source code directory path of the store EJB 30. Explain: Define the source code directory path to the JavaBean 31. Explanation: Define the source code directory path to the SERVLET 32. Explanation: Define the directory path that stores the Web section file (including JSP programs, HTML files, pictures, CSS files, JS scripts, etc.) 33. Explain: Define the development file directory path for the storage component API 34. Explanation: Define the Compile Code Directory Path to Stall EJB 35. Explanation: Define the compile code directory path to the JavaBean 36. Explain: Define the class directory path for web directory 37. Explain: Define the library name of the web directory 38. Explain: Define the name of the compressed document 45. Explain: Define the name of the current component 49. Value = "$ {projectname.components.home} / componentname" /> Explain: Define the directory path of the current component 50. Value = "$ {projectname.componentname.home} / lib / ejb" /> Explanation: Define the EJB Compile Directory Path of the current component 51. Value = "$ {projectname.componentname.home} /build/componentname-ejb.jar" /> Explain: Define the path to the EJB package within the current component 52. Value = "$ {projectname.componentname.home} /build/componentname-ejb-client.jar" /> Explain: Define the path to the EJB client package within the current component 54. Explanation: This is a comment, indicating that the following is the variable that defines the introduction of other components. 55. Value = "ReferencesComponentname" /> Explain: Define the name of the specified component 56. Value = "$ {projectname.components.home} / reference" /> Explain: Define the directory path for the specified component 57. Value = "$ {projectname.referencescomponentname.home} / lib / ejb" /> Explanation: Define the EJB Compile Directory Path for the Specified Components 58. Value = "$ {projectname.referencescomponentname.home} /BUILD/referencescomponentname-ejb.jar "/> Explanation: Define the path to the EJB package within the specified component 59. Value = "$ {projectname.referencescomponentname.home} /BUILD/referencescomponentname-ejb-client.jar "/> Explain: Define the path to the EJB client package within the specified component 61. Value = "$ {jboss.client} /jboss-j2ee.jar: $ {jboss.client} /jnp-client.jar: #jboss.client }/jnp-client.jar:${ jjboss.client} /JBossmq-client.jar: #jboss.client }/jbossx-client.jar: #jboss.client} /concurrent.jar: #jboss.client }/jaas.jar: #jboss.lib} /jboss-jmx.jar: #jboss.home }/server/${ jboss.configuration} /LIB/JBOSSSX.jar: #jboss.home }/server/$ jboss.configuration} /LIB/mail.jar:00:1 (servet-lib.path}:!:: $ {web-classes.dest}: $ {projectname.componentname.classbindir}: $ {Projectname.componentname.ejbjar.client}: $ {Projectname.referenceBindir}: $ {Projectname.referencesComponentname.ejbjar.client} "/> Explain: Define ClassPath and use it when compiling beans. This is a method of defining classpath, and there is another method below. Define ClassPath Location = "$ {jboss.home} / server / $ {jboss.configuration} /lib/jbosssx.jar" /> Location = "$ {jboss.home} / server / $ {jboss.configuration} /lib/mail.jar" /> path> Explanation: This paragraph defines the package file in the application server, such as supporting EJB J2EE.jar, JNP-Client.jar, JBossmq-Client.jar, JBossmq-Client.jar, JBossmq-Client.jar, JBossmq-Client.jar, JBossMQ-Client.jar, Support JavaMail's mail.jar et al. path> Explain: This paragraph defines the package file to use in the project. path> Explanation: This paragraph defines the classpath when compiling servlets, $ {servlet-lib.path} is the Servlet ElCapper specified by the system. Prepare for compiling target> Explain: Clear all files and directories in build, lib directory. target> Explain: Create all directories you want to use in Build, you can join custom directory as needed, such as: Compile EJB section destdir = "$ {EJB-Classes.Dest}" INCLUDES = "com / **" ClasspathRef = "base.path" /> target> Explain: This segment is used to complete compilation EJB and other Help classes. Add a very useful element as needed: Encoding = "$ {javac.encoding}" Tofile = "$ {lib.dir} /ejb/meta-inf/ejb-jar.xml" /> Tofile = "$ {lib.dir} /ejb/meta-inf/jaws.xml" /> Tofile = "$ {lib.dir} /ejb/meta-inf/jboss.xml" /> Tofile = "$ {lib.dir} /ejb/meta-inf/jbosscmp-jdbc.xml" /> target> Explain: This segment is used to copy the EJB deployment document, In JAS, the EJB deployment file is jaws.xml, jboss.xml, jbosscmp-jdbc.xml. Basedir = "$ {lib.dir} / ejb" /> target> Explain: This segment is used to compress the Class and deployment files into a package file, this package file is an EJB component. File = "$ {projectname.referencescomponentname.home} / build / $ {projectname.referencescomponentname.name} -ejb-client.jar" Tofile = "$ {build.dir} / $ {projectname.referencescomponentname.name} -ejb-client.jar "/> Basedir = "$ {lib.dir} / ejb" Excludes = "COM / Projectname / ComponentName / EJB / Componentnameejb.class" /> target> Explain: This segment is used to compress the Class and deployment files into a package file to support the client. Compile Web section destdir = "$ {lib.dir} / web / web-inf / class" INCLUDES = "com / **" Classpath = "$ {build.classpath}" /> target> Explain: This segment is used to complete compilation servlet. Tofile = "$ {lib.dir} /web/web-inf/jboss-web.xml" /> TOFILE = "$ {lib.dir} /web/web-inf/web.xml" /> target> Explain: This segment is used to copy the web deployment file, and the Web deployment file in JAS has JBoss-web.xml. copy> File = "$ {build.dir} / $ {projectname.referencescomponentname.name} -ejb-client.jar" Tofile = "$ {lib.dir} / web / web-inf / lib / $ {projectname.referencescomponentname.name} -ejb-client.jar "/> Basedir = "$ {lib.dir} / web" /> target> Explain: This segment is used to compress all JSP programs, HTML, CSS, pictures, and deployment files into a WAR file. Compilation J2EE Application target> Explain: This segment is used to copy the deployment file of Application. Tofile = "$ {lib.dir} / j2ee / $ {name} -ejb.jar" /> Tofile = "$ {lib.dir} / j2ee / $ {name} -Web.war" /> Basedir = "$ {lib.dir} / j2ee" /> target> Explain: This segment is used to compress the EJB component, support the package and deployment files to the EAR file, which is a J2EE. APPLICATION. Here, it will be explained that, an EAR file may not be generated as needed. Deploy Application fileset> copy> target> Explain: This segment is used to deploy Application, $ {jboss.Deploy} in JAS3.0 is the hot deployment directory of JAS. Create a component's API destdir = "$ {javadoc.dir}" Classpath = "$ {build.classpath}" Encoding = "$ {javadoc.encoding}" Author = "$ {javadoc.author}" Version = "$ {javadoc.version}" Use = "$ {javadoc.usage}" WindowTitle = "$ {project.name} $ {name} Component API" DOCTITLE = "$ {project.name} $ {name} company" Bottom = "CopyRight $ {sign.copyright} $ {project.date} $ {company.signature}. All rights reserved. "> claspath> SourcePath> javadoc> target> Explain: This segment is used to create an API of the component. Here, the designers and codents are intended to comment on the source code according to the Javadoc defined label. Determine the goal of Build target> target> Explain: This segment is used to determine the goal of Build. The default directory is Core, so when you do not add parameters, the system will only generate JAR files and WAR files. If you add a parameter, the system will generate a file as needed, for example, enter Ant Deploy in the command line, the system will generate a JAR file, WAR file, EAR file, and deploy the EAR file. To develop the Java project build specification Define file build.properties in the root of the project, define the shared variables of the project in the file, and is provided to all developers. When developing a Java project, all items build.properties must be the template below. Build.properties · Develop JavaBean's build.xml specification When developing JavaBean, all Javabeans must be the template one by the build.xml below. JavaBean Build.xml Template • Developing EJB Build.xml Specifications When developing EJB, all EJBs must be a template in the following build.xml. Developing EJB Build.xml Templates • Developing Components's build.xml specification When developing Components, all Components must be the template below. Components's Build.xml Template • Develop Application BUILD.XML Specification A) Define file build.properties in the root of Application defines the share variables of Application to all developers. When developing an Application, build.properties under Application must be the template. BUILD.PROPERTIES Template under Application B) When developing Application, all Application must be the template below. Build.xml Templates under Application 2002-7-5 (Edit Sunny )