Running Ehcache and Terracotta from Ant

A few weeks ago I blogged about the fantastic tc-maven plugin which works just as well as the Jetty plugin and makes life easy for Maven-based developers. My surveys from talks I do suggest that the mix of Maven and Ant based builds is 40-60% Maven. Three years ago it was about 10% Maven. Interestingly in Philadelphia the maven usage was 40% versus 60% in San Francisco. But many Ant people have tried Maven and had a less than stellar experience. My own experience was that Maven was as painful as EJB ever was. But it has been getting better over time.

The forthcoming release of Ehcache bundles the Terracotta server and I am very interested in making this as easy as possible for developers. The 2.1-beta kit has instructions for using the tc-maven plugin. The upcoming 2.1 final will also support Ant. Fortunately Ant and Maven interoperate and we will support Ant via the Maven Ant Tasks library.

Installation

Install Maven

Download and install Maven which is just expanding the download somewhere on your file system. Version 2.2.1 or higher is required.

Installing Maven Ant Tasks

There are a couple of choices documented at the Maven site. For simplicity, download the Maven Tasks for Ant 2.1.0 and copy the jar into your $ANT_HOME/lib directory.

Create a pom.xml

Maven requires a pom.xml which is placed in the same directory as build.xml. Use this sample which has all you need:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-terracotta</artifactId>
<version>2.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.terracotta.maven.plugins</groupId>
<artifactId>tc-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<id>run-integration</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-integration</goal>
</goals>
</execution>
<execution>
<id>terminate-integration</id>
<phase>post-integration-test</phase>
<goals>
<goal>terminate-integration</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>terracotta-snapshots</id>
<url>http://www.terracotta.org/download/reflector/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

Additions to build.xml

Add these to build.xml:

    <macrodef name="maven">
        <attribute name="options" default=""/>
        <attribute name="goal"/>
        <attribute name="basedir"/>
        <attribute name="resultproperty" default="maven.result"/>
        <element name="args" implicit="true" optional="true"/>
        <sequential>
            <java classname="org.codehaus.classworlds.Launcher" fork="true"
                  dir="@{basedir}" resultproperty="@{resultproperty}">
                <jvmarg value="-Xmx512m"/>
                <classpath>
                    <fileset dir="${maven.home}/boot">
                        <include name="*.jar"/>
                    </fileset>
                    <fileset dir="${maven.home}/lib">
                        <include name="*.jar"/>
                    </fileset>
                </classpath>
                <sysproperty key="classworlds.conf" value="${maven.home}/bin/m2.conf"/>
                <sysproperty key="maven.home" value="${maven.home}"/>
                <arg line="--batch-mode @{options} @{goal}"/>
            </java>
        </sequential>
    </macrodef>

    <property name="maven.home" value="/Users/gluck/work/apache-maven-2.2.1"/>

    <target name="start_terracotta" description="Starts the Terracotta Server">
        <maven basedir="${basedir}"
               goal="tc:start"
               resultproperty="maven.build.result"
                />
    </target>

    <target name="stop_terracotta" description="Stops the Terracotta Server">
        <property name="maven.home" value="/Users/gluck/work/apache-maven-2.2.1"/>
        <maven basedir="${basedir}"
               goal="tc:stop"
               resultproperty="maven.build.result"
                />
    </target>

Ensure you change your maven.home property value to where you installed Maven.

Usage

Starting Terracotta Server

ant start_terracotta
Buildfile: /Users/gluck/work/ehcache/core/build.xml

start_terracotta:
     

[INFO] Scanning for projects...


[INFO] ------------------------------------------------------------------------


[INFO] Building Unnamed - test:test:jar:1.0


[INFO] task-segment: [tc:start]


[INFO] ------------------------------------------------------------------------


[INFO] [tc:start {execution: default-cli}]


2010-05-01 12:34:26,737 INFO - Terracotta 3.2.1, as of 20100304-100300 (Revision 14673 by cruise@su10mo5 from 3.2)


2010-05-01 12:34:27,018 INFO - Configuration loaded from the Java resource at '/com/tc/config/schema/setup/default-config.xml', relative to class com.tc.config.schema.setup.StandardXMLFileConfigurationCreator.


2010-05-01 12:34:27,152 INFO - Log file: '/Users/gluck/terracotta/server-logs/terracotta-server.log'.


[INFO] ------------------------------------------------------------------------


[INFO] Starting DSO Server


[INFO] [dso start] 2010-05-01 12:34:27,576 INFO - Terracotta 3.2.1, as of 20100304-100300 (Revision 14673 by cruise@su10mo5 from 3.2)


[INFO] OK


[INFO] [dso start] 2010-05-01 12:34:28,065 INFO - Configuration loaded from the Java resource at '/com/tc/config/schema/setup/default-config.xml', relative to class com.tc.config.schema.setup.StandardXMLFileConfigurationCreator.


[INFO] [dso start] 2010-05-01 12:34:28,255 INFO - Log file: '/Users/gluck/terracotta/server-logs/terracotta-server.log'.


[INFO] [dso start] 2010-05-01 12:34:30,759 INFO - Available Max Runtime Memory: 506MB


[INFO] [dso start] 2010-05-01 12:34:30.575::INFO: Logging to STDERR via org.mortbay.log.StdErrLog


[INFO] [dso start] 2010-05-01 12:34:30.620::INFO: jetty-6.1.8


[INFO] [dso start] 2010-05-01 12:34:30.663::INFO: Started TerracottaConnector@0.0.0.0:0


[INFO] [dso start] 2010-05-01 12:34:33,097 INFO - JMX Server started. Available at URL[service:jmx:jmxmp://0.0.0.0:9520]


[INFO] DSO Server status: OK


[INFO] ------------------------------------------------------------------------


[INFO] BUILD SUCCESSFUL


[INFO] ------------------------------------------------------------------------


[INFO] Total time: 14 seconds


[INFO] Finished at: Sat May 01 12:34:33 EST 2010


[INFO] Final Memory: 22M/133M


[INFO] ------------------------------------------------------------------------


[INFO] [dso start] 2010-05-01 12:34:33,840 INFO - Terracotta Server instance has started up as ACTIVE node on 0.0.0.0:9510 successfully, and is now ready for work.

BUILD SUCCESSFUL

Total time: 17 seconds

The Terracotta server will be running on its default port of 9510.

Stopping Terracotta Server

ant stop_terracotta
Buildfile: /Users/gluck/work/ehcache/core/build.xml

stop_terracotta:
     

[INFO] Scanning for projects...


[INFO] ------------------------------------------------------------------------


[INFO] Building Unnamed - test:test:jar:1.0


[INFO] task-segment: [tc:stop]


[INFO] ------------------------------------------------------------------------


[INFO] [tc:stop {execution: default-cli}]


[INFO] ------------------------------------------------------------------------


[INFO] Stopping DSO Server


[INFO] [dso stop] No host or port provided. Stopping the Terracotta server instance at 'localhost', port 9520 by default.


[INFO] OK


[INFO] ------------------------------------------------------------------------


[INFO] BUILD SUCCESSFUL


[INFO] ------------------------------------------------------------------------


[INFO] Total time: 7 seconds


[INFO] Finished at: Sat May 01 12:48:37 EST 2010


[INFO] Final Memory: 21M/123M


[INFO] ------------------------------------------------------------------------

BUILD SUCCESSFUL
Total time: 10 seconds

More Information

The Terracotta plugin is documented on the Forge.

I am interested in people’s experiences using this. Ping me at gluck AT gregluck.com or post questions to the Ehcache Forum.

5 thoughts on “Running Ehcache and Terracotta from Ant

  1. Pingback: Tweets that mention Running Ehcache and Terracotta from Ant - Greg Luck's Blog -- Topsy.com

  2. Pingback: OSCAR

  3. Pingback: WENDELL

  4. Pingback: Greenwich

  5. Pingback: Anonymous

Leave a Reply