Inspired by the Jetty Maven Plugin, the TomEE Maven Plugin is a feature-rich plugin that allows for:

Simply add the following to your pom.xml

<plugin>
  <groupId>org.apache.openejb.maven</groupId>
  <artifactId>tomee-maven-plugin</artifactId>
  <version>1.6.0.2</version>
  <configuration>
    <tomeeVersion>1.6.0.2</tomeeVersion>
    <tomeeClassifier>plus</tomeeClassifier>
  </configuration>
</plugin>

The available commands can be discovered running:

mvn tomee:help

Should print output like the following:

[INFO] Available commands:
[INFO]  - tomee:run: run and wait for the server
[INFO]  - tomee:debug: run in debug mode and wait for the server (alias of run)
[INFO]  - tomee:start: run the server
[INFO]  - tomee:stop: stop the server (to use with start)
[INFO]  - tomee:configtest: run configtest tomcat command
[INFO]  - tomee:deploy <path>: deploy path archive
[INFO]  - tomee:undeploy <path>: undeploy path archive. Note it should be the same path than the one used in deploy command
[INFO]  - tomee:list: list ejbs deployed
[INFO]  - tomee:build: build tomee but does not start it
[INFO]  - tomee:help: this

Note that for the tomee:deploy and tomee:undeploy goals, the path can either be specified within the section of the pom.xml using the parameter, or it can be passed via the user property tomee-plugin.archive. If a relative path is passed for the deploy path archive, this must be relative to the TomEE server.

Note 2: running tomee maven plugin you can type 'quit' directly in the console to shutdown correctly the server. 'reload' is also available when internal openejb application is deployed.

Available configuration elements:

Optional Parameters

Name Type Since Description
apacheRepos String - repository to use for snapshots
Default value is: snapshots.
User property is: tomee-plugin.apache-repos.
appDir String - relative to tomee.base.
Default value is: apps.
apps List - folder for applications (jar and ear)
args String - additional JVM options (-Xmx, -Xms, ...)
User property is: tomee-plugin.args.
bin File - bin directory to sync
Default value is: ${project.basedir}/src/main/tomee/bin.
User property is: tomee-plugin.bin.
catalinaBase File - catalina.base
Default value is: ${project.build.directory}/apache-tomee.
config File - conf directory to sync
Default value is: ${project.basedir}/src/main/tomee/conf.
User property is: tomee-plugin.conf.
debug boolean - debug (remote debuggding)
Default value is: false.
User property is: tomee-plugin.debug.
debugPort int - remote debugging port
Default value is: 5005.
User property is: tomee-plugin.debugPort.
deployOpenEjbApplication boolean - should internal app be deployed (needed for some features)
Default value is: false.
User property is: tomee-plugin.deploy-openejb-internal-application.
keepServerXmlAsthis boolean - should server.xml ports be replaced to respect what is in the pom
Default value is: false.
User property is: tomee-plugin.keep-server-xml.
lib File - lib folder to sync
Default value is: ${project.basedir}/src/main/tomee/lib.
User property is: tomee-plugin.lib.
libDir String - relative to tomee.base.
Default value is: lib.
libs List - supported formats: --> groupId:artifactId:version... --> unzip:groupId:artifactId:version... --> remove:prefix (often prefix = artifactId)
password String - password when using openejb internal application in secured mode
User property is: tomee-plugin.pwd.
path String - The path of the archive to deploy
User property is: tomee-plugin.archive.
quickSession boolean - should secure random be replaced by random for session id generation
Default value is: true.
User property is: tomee-plugin.quick-session.
realm String - realm used by openejb internal application when secured
User property is: tomee-plugin.realm.
reloadOnUpdate boolean - should app be auto redeployed when updating a binary
Default value is: false.
User property is: tomee-plugin.reload-on-update.
removeDefaultWebapps boolean - remove host-manager, docs, ROOT, manager
Default value is: true.
User property is: tomee-plugin.remove-default-webapps.
removeTomeeWebapp boolean - remote tomee webapp
Default value is: false.
User property is: tomee-plugin.remove-tomee-webapps.
skipCurrentProject boolean - don't deploy current project
Default value is: false.
User property is: tomee-plugin.skipCurrentProject.
synchronization Synchronization - resource synchronization block
systemVariables Map - system properties (in map format)
tomeeAjpPort int - ajp port
Default value is: 8009.
User property is: tomee-plugin.ajp.
tomeeArtifactId String - Default value is: apache-tomee.
User property is: tomee-plugin.artifactId.
tomeeClassifier String - classifier to use (webprofile, jaxrs, plus)
Default value is: webprofile.
User property is: tomee-plugin.classifier.
tomeeGroupId String - tomee groupId (for custom distrib)
Default value is: org.)apache.openejb.
User property is: tomee-plugin.groupId.
tomeeHost String - tomee host
Default value is: localhost.
User property is: tomee-plugin.host.
tomeeHttpPort int - http port
Default value is: 8080.
User property is: tomee-plugin.http.
tomeeHttpsPort Integer - https port
User property is: tomee-plugin.https.
tomeeShutdownPort int - shutown port
Default value is: 8005.
User property is: tomee-plugin.shutdown.
tomeeVersion String - tomee version
Default value is: -1.
User property is: tomee-plugin.version.
user String - user when openejb internal webapp is secured
User property is: tomee-plugin.user.
warFile File - application to deploy
Default value is: ${project.build.directory}/${project.build.finalName}.${project.packaging}.
webappDir String - relative to tomee.base.
Default value is: webapps.
webapps List - webapps directory if custom

Some more tweak

The lib tag allows to enrich the container with some additional librairies.

It supports some interesting pattern to complete the default maven format.

Note: the name tweak can be used to rename applications too

Provisioning Example

This plugin is also usable in projects which are not war. For instance you can use it in a pom project to setup a TomEE install, add libraries, deploy apps then run the server.

  <plugin>
    <groupId>org.apache.openejb.maven</groupId>
    <artifactId>tomee-maven-plugin</artifactId>
    <version>1.6.0.2</version>
    <configuration>
      <tomeeVersion>1.6.0.2</tomeeVersion>
      <tomeeClassifier>plus</tomeeClassifier>
      <debug>false</debug>
      <debugPort>5005</debugPort>
      <args>-Dfoo=bar</args>
      <config>${project.basedir}/src/test/tomee/conf</config>
      <libs>
        <lib>mysql:mysql-connector-java:5.1.20</lib>
      </libs>
      <webapps>
         <webapp>org.superbiz:myapp:4.3?name=ROOT</webapp>
         <webapp>org.superbiz:api:1.1</webapp>
      </webapps>
      <apps>
          <app>org.superbiz:mybugapp:3.2:ear</app>
      </apps>
      <libs>
          <lib>mysql:mysql-connector-java:5.1.21</lib>
          <lib>unzip:org.superbiz:hibernate-bundle:4.1.0.Final:zip</lib>
          <lib>remove:openjpa-</lib>
      </libs>
    </configuration>
  </plugin>

Auto Reloading example

<plugin>
  <groupId>org.apache.openejb.maven</groupId>
  <artifactId>tomee-maven-plugin</artifactId>
  <version>1.6.0.2</version>
  <configuration>
    <synchronization>
      <extensions>
        <extension>.class</extension> <!-- if you want to update each time you build with mvn compile -->
      </extensions>
    </synchronization>
    <reloadOnUpdate>true</reloadOnUpdate>
  </configuration>
</plugin>

Synchronization block supports the following configuration:

reloadOnUpdate means to reload the context (webapp). It means undeploying/redeploying it.