TomEE can be run as a daemon using the jsvc tool from the commons-daemon project. Source tarballs for jsvc are included with the TomEE binaries, and need to be compiled. Building jsvc requires a C ANSI compiler (such as GCC), GNU Autoconf, and a JDK.

Before running the script, the JAVA_HOME environment variable should be set to the base path of the JDK. Alternately, when calling the ./configure script, the path of the JDK may be specified using the --with-java parameter, such as ./configure --with-java=/usr/java.

Using the following commands should result in a compiled jsvc binary, located in the $TOMEE_HOME/bin folder. This assumes that GNU TAR is used, and that TOMEE_HOME is an environment variable pointing to the base path of the TomEE installation.

Please note that you should use the GNU make (gmake) instead of the native BSD make on FreeBSD systems.

Building

cd $TOMEE_HOME/bin
tar xzvf commons-daemon-native.tar.gz
cd commons-daemon-1.0.7-native-src/unix/
./configure
make
chmod 755 jsvc
mv jsvc ../..

Note that the commons-daemon-1.0.7-native-src directory may have a slightly different version number.

Starting (unix)

sudo "$TOMEE_HOME/bin/jsvc" -cp "$TOMEE_HOME/bin/bootstrap.jar:$TOMEE_HOME/bin/tomcat-juli.jar" \
    "-javaagent:$TOMEE_HOME/lib/openejb-javaagent.jar" -outfile "$TOMEE_HOME/logs/catalina.out" \
    -errfile "$TOMEE_HOME/logs/catalina.err" org.apache.catalina.startup.Bootstrap

Starting (osx)

For a 64-bit JVM such as OSX Lion

sudo arch -arch x86_64 "$TOMEE_HOME/bin/jsvc" -jvm server -cp "$TOMEE_HOME/bin/bootstrap.jar:$TOMEE_HOME/bin/tomcat-juli.jar" \
    "-javaagent:$TOMEE_HOME/lib/openejb-javaagent.jar" -outfile "$TOMEE_HOME/logs/catalina.out" \
    -errfile "$TOMEE_HOME/logs/catalina.err" org.apache.catalina.startup.Bootstrap

For a 32-bit JVM

sudo arch -arch i386 "$TOMEE_HOME/bin/jsvc" -jvm server -cp "$TOMEE_HOME/bin/bootstrap.jar:$TOMEE_HOME/bin/tomcat-juli.jar" \
    "-javaagent:$TOMEE_HOME/lib/openejb-javaagent.jar" -outfile "$TOMEE_HOME/logs/catalina.out" \
    -errfile "$TOMEE_HOME/logs/catalina.err" org.apache.catalina.startup.Bootstrap

Note on formatting

Note that \ at the end of each line is unix syntax to keep everything effectively as one line and one command. The command is simply too long to show as one line on a fixed width html page. The \ can be removed as long as the resulting command is one long line.

Issues

Ensure your $TOME_HOME and $JAVA_HOME variables are set correctly. You should see similar output with the following two commands

mingus:~ 01:51:37
$ ls $TOMEE_HOME
LICENSE     RELEASE-NOTES   bin     endorsed    logs        webapps
NOTICE      RUNNING.txt conf        lib     temp        work

mingus:~ 01:51:46
$ ls $JAVA_HOME
bin bundle  lib man

Note on OSX, $JAVA_HOME should be set to /System/Library/Frameworks/JavaVM.framework/Home