Some templating in TomEE

Having some templetized configuration file is a great feature for the cloud. Here how to deal with it using TomEE.

Tomcat has some templating features.

Typically you can replace the ports in the server.xml by something like ${mySuperport} and set mySuperPort system property when you launch Tomcat. This still works in TomEE.

Here a sample:

<?xml version='1.0' encoding='utf-8'?>
<Server port="${tomee.shutdown}" shutdown="SHUTDOWN">
  <Listener className="org.apache.tomee.catalina.ServerListener" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <Service name="Catalina">
    <Connector port="${tomee.http}" protocol="HTTP/1.1"
               connectionTimeout="20000" />

    <Engine name="Catalina" defaultHost="${}">
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true" />

Then simply add to CATALINA_OPTS these properties:

export CATALINA_OPTS=" -Dtomee.http=8080 -Dtomee.shutdown=8005"

That’s cool but TomEE can come (in particular the plus version) with some additional services using additional ports. For instance the ssh console uses another port. Or let say you simply want to change dynamically your configuration.

These kind of services have their own configuration in $CATALINA_BASE/conf/conf.d/.properties. For instance for the ssh console it is: $CATALINA_BASE/conf/conf.d/

Until 1.0.0 release to override these property values you had to set the property <service-name>.<attribute>. For instance to disable SOAP webservices (the service is called “cxf”) you had to set:

export CATALINA_OPTS="-Dcxf.disabled=true"

The good part is you don’t need to change the configuration file at all. But sometimes this change can be what you want. Or simply to be consistent with Tomcat you want to use ${xx} values. That’s now possible on trunk.

Simply edit <service name>.properties file and change the value to ${foo}. Then simply set the system property “foo” like for Tomcat.

Now your TomEE configuration is ready to be templetized (cloud, did you say cloud?).

I would like to thank Neale Rudd from for his help on this topic.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s