O'Reilly logo

Java Extreme Programming Cookbook by Brian M. Coyner, Eric M. Burke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Starting Tomcat with Ant

Problem

You want to start Tomcat using Ant.

Solution

Create a target that invokes the custom Ant task com.oreilly.javaxp.tomcat.tasks.StartTomcatTask.

Discussion

Typically, a server is started from a command prompt using a predefined script distributed with the server. To facilitate test-first programming, we need the ability to start Tomcat from Ant. Specifically, the Ant build process needs to start Tomcat and wait for Tomcat to become available before continuing. As of this writing, there is no generic way to solve this problem. So we created a new Ant task called StartTomcatTask to provide the functionality needed.

Example 10-4 shows the AbstractTomcatTask , which is the base class for the StartTomcatTask (Example 10-5) and StopTomcatTask (Recipe 10.7). This task extends Ant’s Task, and is directly referenced in a buildfile.

Example 10-4. AbstractTomcatTask

package com.oreilly.javaxp.tomcat.tasks; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; public abstract class AbstractTomcatTask extends Task { private TomcatSupport tomcatSupport; /** * Overrides the base class implementation to instantiate the * <code>TomcatSupport</code> class. */ public void init( ) { this.tomcatSupport = new TomcatSupport(this, getScriptToExecute(), isStarting( )); } /** * @return the name of the script to execute. For Tomcat 4.0 and * higher a valid filename might be 'startup'. The name of the script * should <strong>not</strong> include the extension. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required