in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

Java Tools for Extreme programming mastering open source tools including - Hightower R.

Hightower R. Java Tools for Extreme programming mastering open source tools including - Wiley publishing , 2002. - 417 p.
ISBN: 0-471-20708
Download (direct link): javatoolsforextremeprog2002.pdf
Previous << 1 .. 23 24 25 26 27 28 < 29 > 30 31 32 33 34 35 .. 159 >> Next

<target name="all" depends="clean,fetch,build,test,docs,deploy">
<target name="clean">
<target name="fetch">
<target name="build" depends="clean">
<target name="test" depends="build">
<target name="docs" depends="clean">
<target name="deploy" depends="build, test">
<target name="publish" depends="deploy">
The project is a group of related targets. Although you can define any target you like, a set of standard naming conventions exists, as we discuss in the section "Standard Targets."
Listing 4.1 contains a build target that could, for example, compile the source and create JAR and WAR files. Notice that the build target depends on the execution of the tasks associated with the clean target (the tasks
are not shown). The test target in turn depends on the build target. The order of the dependencies expressed with the target's "depend" attribute in this example is quite logical. For example, you can't test the code if it does not build—after the code is built, it's tested.
You can give targets any name that you like. However, people generally use common Ant names to create buildfiles, as discussed in the next section.
Standard Targets
Steve Loughran wrote an Ant guide called Ant In Anger. This guide explains many pitfalls and recommends ways to use Ant. Two very useful suggestions are a list of names for targets and how to divide buildfiles.
The following are some of Steve's recommended names for Ant top-level targets:
? test— Run the junit tests
? clean— Clean out the output directories
? deploy— Ship the JARs, WARs, and so on to the execution system
? publish— Output the source and binaries to any distribution site
? fetch— Get the latest source from the CVS tree
? docs/javadocs— Outputs the documentation
? all— Perform clean, fetch, build, test, docs, and deploy
? main— The default build process (usually build or build and test)
The following are some recommended names for Ant internal targets:
? init— Initialize properties and perform other intialization tasks; read in peruser property files
? init-debug— Initialize debug properties
? init-release— Initialize release properties
? compile— Perform the actual compilation
? link/jar— Make the JARs or equivalent
? staging— Carry out any pre-deployment process in which the output is dropped off and then tested
before being moved to the production site.
We'll discuss some of the thoughts from Ant in Anger in this chapter and the next; however, we strongly suggest that you read this guide, because it contains excellent guidelines for using Ant. The guide is included with the Ant binary distribution under the docs directory.
Before we go any further, let's look at a simple example to cement some of the concepts of Ant. The next section presents a straightforward buildfile.
Simple Example
Let's start with a very small, straight forward example of using Ant. We will begin with the now-infamous "hello world" example. It will create an output directory and then compile a Java source file called to the output directory.
The Java source file is stored in ./src/xptoolkit as follows: package xptoolkit; public class HelloWorld{
public static void main(String []args){
System.out.println("Hello World!");
The following ant buildfile, build.xml, compiles the source file:
<project name="hello" default="compile">
<target name="prepare">
<mkdir dir="/tmp/classes"/>
<target name="compile" depends="prepare"> <javac srcdir="./src" destdir="/tmp/classes"/> </target>
When you run Ant from the command line, it looks for a buildfile called build.xml in the current working directory. To specify a buildfile with a different name, you must specify the buildfile name using the -buildfile command-line argument (discussed in detail later).
Notice that the hello project has targets called compile and prepare. The hello project specifies the compile target as the default target. The compile target has a task called javac, which compiles the location specified by srcdir to the directory specified by the "destdir" attribute. The built-in task javac compiles Java source. Because the default directory location for a project is the current working directory, the javac task will look for a directory called src (srcdir="./src") under the current working directory and compile the contents of the src directory to the /tmp/classes directory.
Notice that the compile target's "depends" attribute points to the prepare target (depends="prepare"). As a result, all the tasks associated with the prepare target will be executed before the tasks associated with the compile target. This is a good thing—otherwise, the javac task might try to compile the source code to a directory that did not exist.
As you can see, you can use the targets and their dependencies to logically build, deploy, and test a complex system. The next section shows you how to set up your Ant buildfiles.
Previous << 1 .. 23 24 25 26 27 28 < 29 > 30 31 32 33 34 35 .. 159 >> Next