< Zurück | Inhalt | Weiter >

23.4.1 Ant and CVS

In previous chapters we’ve talked about CVS for managing sources and Ant for automating our builds. The first step to making all this work together is something that we should have covered sooner—using CVS with Ant.2

Example 23.7 is a simple Ant buildfile (build.xml) that will let you get the source from your CVS repository by supplying a particular CVS tag. You name the tag (which you would have previously applied to your sources) and this Ant target will check out that version. The files are put in the srctree directory off of the basedir of the Ant project.

You will have to modify this script to make it fit your environment. The cvsRoot and csvRsh values correspond to the CVSROOT and CVS_RSH environ- ment variables that you would otherwise have set for working with CVS. The package attribute should be set to the project directory that you would specify when you check out sources. The directory specified by the dest attribute will be created if it doesn’t exist.

The next task to accomplish with Ant is the construction of the EAR, WAR, and JAR files. Since all three files are essentially just JAR files, we can use the Ant jar task. The EAR contains a WAR and a JAR, and those in turn contain Java class files (and a few miscellaneous files). Using the depends attribute, we can build them in steps.


image

2. So, aren’t you glad that you’ve kept reading and gotten this far? Ah, the rewards of persistence!

23.4 Maintaining a Distributed Application 517

image


image

Example 23.7 An Ant target for checking out source from CVS

<?xml version="1.0"?>

<!-- ++++++++++++++++++++++++++++++++++++++++++++++ -->

<!-- retrieve our sources by tag name -->

<!-- invoke with: ant -DTAG=puttaghere -->

<!-- ++++++++++++++++++++++++++++++++++++++++++++++ -->


<project name="sources" default="src" basedir=".">


<!-- src target -->

<target name="src">

<cvs cvsRoot=":ext:user@hostaddress:/usr/lib/cvs/cvsroot" cvsRsh="/usr/bin/ssh"

package="projectdir/subproj" dest="srctree"

tag="${TAG}">

</cvs>

</target>


</project>


image


Our example (see the book’s Web site3 for the full listing) only copies prebuilt XML files (the deployment descriptors) into place to be included in the JAR, WAR, and EAR files. For small examples like ours, building the de- ployment descriptors by hand is not a difficult task. But larger, more complex projects will benefit from further automation. Most J2EE servers come with tools to help build such things. These tools tend to be specific to the particulars of their products. Since the J2EE specification allows for certain vendor varia- tions and configuration differences, they can be helpful in configuring things for your specific vendor’s version. But being dependent on them for your de- ployment is a subtle way to become locked into their product. Another good choice—one that avoids this vendor lock-in—is the Open Source tool XDoclet.