How to use BTM as the transaction manager in Jetty 6.x
These instructions have been verified against BTM 1.3.1.
| Jetty 6 JNDI support Before you can get the transaction manager and datasources via JNDI ENC (URLs starting with |
Contents
Step 1: Copy the BTM jars
Copy the following jars from the BTM distribution in the jetty6 lib/ext/ directory:
- btm-1.3.1.jar
- geronimo-jta_1.0.1B_spec-1.0.1.jar
- slf4j-api-1.5.2.jar
- btm-jetty6-lifecycle.jar
Also copy the following jars in the jetty6 lib/ext/ directory:
You will also need to copy your JDBC driver's JAR file in that same folder. In this example, we've used Derby 10.3.2.1 so we copied derby.jar in Jetty's lib/ext/ directory.
Step 2: Configure BTM as the transaction manager
Copy the following into your jetty config file:
Do not forget to create the work/ directory in Jetty's home folder !
| Hint This will make the transaction manager available under this JNDI URL: java:comp/UserTransaction. |
Step 3: Configure DataSources that are transaction aware
The easiest way to do this is to use the DataSource that ship with BTM.
Here's an example of using BTM with a DataSource that implements javax.sql.XADataSource:
The bitronix.tm.resource.jdbc.PoolingDataSource implements javax.sql.DataSource and interacts with the javax.sql.XADataSource provided in this instance by Derby.
| Hint This datasource will be available under this JNDI URL: java:comp/env/jdbc/mydatasource. |
If your database vendor does not provide an XADataSource, you can use BTM's bitronix.tm.resource.jdbc.lrc.LrcXADataSource as the XADataSource to allow your database connections to be controlled by the transaction manager:
| Hint This datasource will be available under this JNDI URL: java:comp/env/jdbc/exampleNonXADS. |
Again, we've used Derby as an example, but as the LrcXADataSource uses only the class name and url of a java.sql.Driver, you can use it with any database providing a JDBC driver.
Step 4: Configure datasources references in your web.xml
Before your code can access configured datasources via JNDI ENC URLs, you need to declare resource references in your web.xml:
Now you can perform JNDI lookups on those URLs to access the configured datasources:
and you can do JNDI lookups on this URL to access the transaction manager:
