I am already for a while busy to get a J2EE application running. I did not want to use software other than open source. I first tried Glassfish and this worked fine. I was not happy with the fact that Oracle was very present. I searched the web and came upon the site of OpenEJB. They created an installation with Tomcat7 included. I installed it and after some modifications to my application it was working. At the same time I replaced MySQL with PostgreSQL for the same reason as Glassfish.

I already had a Tomcat (5.5) running. I could replace it with Tomee. To me the upgrades for Tomee looked like the new installation of Tomee and redo all configurations. This seemed too much work. Fortunately you can also install Tomee as an application on Tomcat7. Now the upgrades of Tomcat can be done through the 'normal' Debian procedure. Since Tomcat7 is only available in test I downloaded the .deb packages (tomcat7 and tomcat7-admin) and did the installation by hand. I moved my wiki (VqWiki) and it worked. Now I was ready to install Tomee. This looked more simple as it was.

Tomee needs 2 jar files in the Tomcat lib directory. These jars are:

  • openejb-javaagent.jar
  • tomee-loader-1.5.0.jar

You also need to modify some configuration files. Tomee has the option to do it from the Tomee application but in the installation the directories are owned by root who is the only one with write access. I used the source and the "Tomee with build-in Tomcat7" package.


Change the line with JAVA_OPTS= in:

# Default Java options 
# Set java.awt.headless=true if JAVA_OPTS is not set so the 
# Xalan XSL transformer can work without X11 display on JDK 1.4+ 
# It also looks like the default heap size of 64M is not enough for most cases 
# so the maximum heap size is set to 128M 
if [ -z "$JAVA_OPTS" ]; then 
        JAVA_OPTS="-Djava.awt.headless=true -XX:+DisableExplicitGC -Xmx512M -XX:MaxPermSize=384m" 


Add the middle 2 lines to the file. Use the outer 2 lines to find the right place.

<Server port="8005" shutdown="SHUTDOWN"> 
  <!-- TomEE plugin for Tomcat --> 
  <Listener className="org.apache.tomee.loader.OpenEJBListener" /> 
  <!-- Security listener. Documentation at /docs/config/listeners.html


This file needs to be created. It has all kind of values that are commented so it seems not that important.

# all this properties are added at JVM system properties at startup
# here some default Apache TomEE system properties
# for more information please see

# openejb.check.classloader = false
# openejb.check.classloader.verbose = false

# tomee.jaxws.subcontext = webservices
# tomee.jaxws.oldsubcontext = false

# openejb.servicemanager.enabled = true
# openejb.descriptors.output = false
# openejb.strict.interface.declaration = false
# openejb.conf.file = conf/tomee.xml
# openejb.debuggable-vm-hackery = false
# openejb.validation.skip = false
# openejb.webservices.enabled = true
# openejb.validation.output.level = MEDIUM
# openejb.user.mbeans.list = *
# openejb.deploymentId.format = {appId}/{ejbJarId}/{ejbName}
# openejb.jndiname.format = {deploymentId}{interfaceType.annotationName}
# openejb.deployments.package.include = .*
# openejb.deployments.package.exclude = 
# openejb.autocreate.jta-datasource-from-non-jta-one = true
# openejb.altdd.prefix = 
# org.apache.openejb.default.system.interceptors = 
# openejb.jndiname.failoncollision = true
# openejb.wsAddress.format = /{ejbDeploymentId}
# org.apache.openejb.server.webservices.saaj.provider = 
# = true
# openejb.nobanner = true
# openejb.offline = false
# = true
# openejb.exclude-include.order = include-exclude
# openejb.additional.exclude =
# openejb.additional.include =
# openejb.crosscontext = false
# openejb.jsessionid-support = 
# openejb.myfaces.disable-default-values = true
# openejb.web.xml.major = 
# javax.persistence.provider = org.apache.openjpa.persistence.PersistenceProviderImpl
# javax.persistence.transactionType = 
# javax.persistence.jtaDataSource = 
# javax.persistence.nonJtaDataSource = 


Add (at least) the group tomee-admin.

  <role rolename="tomee-admin"/> 
  <role rolename="manager-gui"/> 
  <user username="tomcat" password="tomcat" roles="tomee-admin,manager-gui"/>


This file needs to be modified. Add the following lines at the end of it.

Cannot find it yet :-(


Add the first 4 lines. Use the last line to find the right place.

# Add OpenEJB javaagent
if [ -r "$CATALINA_HOME"/lib/openejb-javaagent.jar ]; then
  JAVA_OPTS=""-javaagent:$CATALINA_HOME/lib/openejb-javaagent.jar" $JAVA_OPTS"

# ----- Execute The Requested Command -----------------------------------------

Final Steps

Now the best thing to do is to change the ownership of /etc/tomcat7 to tomcat7 and deploy the tomee.war. The application will create the file /etc/tomcat7/openejb.xml. Once this file is created you can change the ownership back to root again. Creating an empty /etc/tomcat7/openejb.xml does not work. Tomee will refuse to work because the file is not correct.

I was now able to deploy my application. I defined my datasource in openejb.xml but when I deployed my application I got the error that the tomcat-jdbc was missing. By default this jar is not included in the Debian Tomcat7 package nor the Tomcat7 Admin package. I copied it by hand and the same for the PostgreSQL library.

Mission accomplished. I now have an J2EE Application Server with an application. I need to clean-up the application and then I will publish it here on my site.

To be continued...

Am I 100% happy? No not really. I want to include both Sonar and Nexus on my Tomcat7 with Tomee. I do not need those applications much and only for myself. My server has limited memory (1Gb) so I cannot have 3 application servers running. I was able to run Sonar on Tomcat7 without Tomee but when I have them both on the same server then Tomee is somehow messing up Sonar. I guess that it will be the same for Nexus. So what to do? You have the possibility to exclude classes from Tomee. I have to figure out how.