This page was based on outdated content and configuration that no longer works. Looking for our certified way of configuring Atomikos 5.0.98 in Tomcat? Our commercial product includes built-in Tomcat integration; start your free trial here:
Free TrialIt is possible to fully integrate the Atomikos transaction manager into Tomcat. Doing it this way makes the transaction manager shared across all web applications exactly like with any full-blown J2EE server.
TOMCAT_HOME/common/lib
folder). If you dont do that, you will get a NoClassDefFoundErrors or a ClassNotFoundException or even a ClassCastException during your web application deployment.
This is not a limitation of Atomikos nor of Tomcat but of the J2EE class loading design that both Tomcat and Atomikos must follow.
Installation is quite simple, it just involves copying some JAR files, a propery file and editing some Tomcat configuration files.
TOMCAT_HOME/server/lib
folder: atomikos-tomcat-lifecycle.jar
This JAR contains a single class file that is a Tomcat lifecycle lsitener: it listens for Tomcat's startup and shutdown events and start or stop the transaction manager accordingly. Here is its source code:
package com.atomikos.tomcat; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.atomikos.icatch.jta.UserTransactionManager; import com.atomikos.icatch.system.Configuration; public class AtomikosLifecycleListener implements LifecycleListener { private static Log log = LogFactory.getLog(AtomikosLifecycleListener.class); private UserTransactionManager utm; public void lifecycleEvent(LifecycleEvent event) { if (Lifecycle.START_EVENT.equals(event.getType())) { if (utm == null) { log.info("starting Atomikos Transaction Manager " + Configuration.VERSION); utm = new UserTransactionManager(); } } else if (Lifecycle.STOP_EVENT.equals(event.getType())) { if (utm != null) { log.info("shutting down Atomikos Transaction Manager"); utm.close(); } } } }
You should also copy the transactions-hibernate3.jar and/or transactions-hibernate2.jar at the same location if you're planning to use Hibernate.
TOMCAT_HOME/common/classes
folder: jta.properties
TOMCAT_HOME/conf/server.xml
file. At the beginning of the file you should see these four lines:
<Listener className="org.apache.catalina.core.AprLifecycleListener" /> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
Right after the last one, add this fifth one:
<Listener className="com.atomikos.tomcat.AtomikosLifecycleListener" />
TOMCAT_HOME/conf/context.xml
file. At the beginning of the file you should see this line:
<WatchedResource>WEB-INF/web.xml</WatchedResource>
Right after it, add that one:
<Transaction factory="com.atomikos.icatch.jta.UserTransactionFactory" />
Here is a sample application that demonstrates how you can run TransactionsEssentials in a web application after it has been globally installed.
It is a simple blueprint application that shows and updates the content of a single Derby database.
Download the sample application here: dbtest.war To install it, simply copy the WAR file in Tomcat's webapps folder. You also need to install Derby's JDBC driver inTOMCAT_HOME/common/lib
.
You can then access it via this URL: http://localhost:8080/dbtest/.
TOMCAT_HOME/work
or else, the existing one is reused.
TOMCAT_HOME/work
.
INFO: starting Atomikos Transaction Manager 3.2.2
INFO: shutting down Atomikos Transaction Manager