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:
     [java] [INFO] Scanning for projects...
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Building Unnamed - test:test:jar:1.0
     [java] [INFO]    task-segment: [tc:start]
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] [tc:start {execution: default-cli}]
     [java] 2010-05-01 12:34:26,737 INFO - Terracotta 3.2.1, as of 20100304-100300 (Revision 14673 by cruise@su10mo5 from 3.2)
     [java] 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.
     [java] 2010-05-01 12:34:27,152 INFO - Log file: '/Users/gluck/terracotta/server-logs/terracotta-server.log'.
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Starting DSO Server
     [java] [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)
     [java] [INFO] OK
     [java] [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.
     [java] [INFO] [dso start] 2010-05-01 12:34:28,255 INFO - Log file: '/Users/gluck/terracotta/server-logs/terracotta-server.log'.
     [java] [INFO] [dso start] 2010-05-01 12:34:30,759 INFO - Available Max Runtime Memory: 506MB
     [java] [INFO] [dso start] 2010-05-01 12:34:30.575::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
     [java] [INFO] [dso start] 2010-05-01 12:34:30.620::INFO:  jetty-6.1.8
     [java] [INFO] [dso start] 2010-05-01 12:34:30.663::INFO:  Started TerracottaConnector@0.0.0.0:0
     [java] [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]
     [java] [INFO] DSO Server status: OK
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] BUILD SUCCESSFUL
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Total time: 14 seconds
     [java] [INFO] Finished at: Sat May 01 12:34:33 EST 2010
     [java] [INFO] Final Memory: 22M/133M
     [java] [INFO] ------------------------------------------------------------------------
     [java] [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:
     [java] [INFO] Scanning for projects...
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Building Unnamed - test:test:jar:1.0
     [java] [INFO]    task-segment: [tc:stop]
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] [tc:stop {execution: default-cli}]
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Stopping DSO Server
     [java] [INFO] [dso stop] No host or port provided. Stopping the Terracotta server instance at 'localhost', port 9520 by default.
     [java] [INFO] OK
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] BUILD SUCCESSFUL
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Total time: 7 seconds
     [java] [INFO] Finished at: Sat May 01 12:48:37 EST 2010
     [java] [INFO] Final Memory: 21M/123M
     [java] [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.

By Greg Luck

As Terracotta’s CTO, Greg (@gregrluck) is entrusted with understanding market and technology forces and the business drivers that impact Terracotta’s product innovation and customer success. He helps shape company and technology strategy and designs many of the features in Terracotta’s products. Greg came to Terracotta on the acquisition of the popular caching project Ehcache which he founded in 2003. Prior to joining Terracotta, Greg served as Chief Architect at Australian online travel giant Wotif.com. He also served as a lead consultant for ThoughtWorks on accounts in the United States and Australia, was CIO at Virgin Blue, Tempo Services, Stamford Hotels and Resorts and Australian Resorts and spent seven years as a Chartered Accountant in KPMG’s small business and insolvency divisions. He is a regular speaker at conferences and contributor of articles to the technical press.

5 comments

  1. Pingback: OSCAR
  2. Pingback: WENDELL
  3. Pingback: Greenwich
  4. Pingback: Anonymous

Comments are closed.