Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Bitronix Transaction Manager
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h1>How to use BTM as the transaction manager in Jetty 6.x</h1> <p>These instructions have been verified against BTM 1.1.</p> <table class="wysiwyg-macro" data-macro-name="info" data-macro-parameters="title=Jetty 6 JNDI support" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2luZm86dGl0bGU9SmV0dHkgNiBKTkRJIHN1cHBvcnR9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>Before you can get the transaction manager and datasources via JNDI ENC (URLs starting with <code>java:comp/</code>), you first need to configure Jetty with support for it.<br class="atl-forced-newline" />See <a href="http://docs.codehaus.org/display/JETTY/JNDI">Jetty's JNDI documentation page</a>.</p></td></tr></table> <h4>Contents</h4> <img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e3RvYzptYXhMZXZlbD0zfG1pbkxldmVsPTJ9&locale=en_GB&version=2" data-macro-name="toc" data-macro-parameters="maxLevel=3|minLevel=2"> <h2>Step 1: Copy the BTM jars</h2> <p>Copy the following jars from the BTM distribution to the jetty6 <code>lib/</code> directory:</p> <ul> <li>btm-1.1.jar</li> <li>geronimo-spec-jta-1.0.1B-rc4.jar</li> <li>slf4j-jdk14.jar (<em>or any other one available <a class="confluence-link" href="/display/BTM/DebugLogging12" data-linked-resource-id="7995434" data-linked-resource-type="page" data-linked-resource-default-alias="DebugLogging12" data-base-url="http://docs.codehaus.org">here</a></em>)</li> </ul> <h2>Step 2: Configure BTM as the transaction manager</h2> <p>Copy the following into your jetty config file:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="XML" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6WE1MfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <Call name="getConfiguration" class="bitronix.tm.TransactionManagerServices"> <Set name="serverId">jetty-btm-node0</Set> <Set name="logPart1Filename"><SystemProperty name="jetty.home" default="." />/work/btm1.tlog</Set> <Set name="logPart2Filename"><SystemProperty name="jetty.home" default="." />/work/btm2.tlog</Set> </Call> <New class="org.mortbay.jetty.plus.naming.Transaction"> <Arg> <Call name="getTransactionManager" class="bitronix.tm.TransactionManagerServices" /> </Arg> </New> </pre></td></tr></table> <table class="wysiwyg-macro" data-macro-name="tip" data-macro-parameters="title=Hint" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3RpcDp0aXRsZT1IaW50fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>This will make the transaction manager available under this JNDI URL: <strong>java:comp/UserTransaction</strong>.</p></td></tr></table> <h2>Step 3: Configure DataSources that are transaction aware</h2> <p>The easiest way to do this is to use the <code>DataSource</code> that ship with BTM.</p> <table class="wysiwyg-macro" data-macro-name="note" data-macro-parameters="title=ordering of XML elements" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vdGU6dGl0bGU9b3JkZXJpbmcgb2YgWE1MIGVsZW1lbnRzfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>It is recommended that the datasources definitions appear before the transaction manager's one in Jetty's XML configuration. If you don't, recovery will be run on <em>all known datasources each time a new one is created</em> instead of just once at transaction manager's startup.<br /> If this is problematic for you, please let us know by voting for <a href="http://jira.codehaus.org/browse/BTM-4">BTM-4</a>.</p></td></tr></table> <p>Here's an example of using BTM with a <code>DataSource</code> that implements <code>javax.sql.XADataSource</code>:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="XML" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6WE1MfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <New id="mydatasource" class="org.mortbay.jetty.plus.naming.Resource"> <Arg>jdbc/mydatasource</Arg> <Arg> <New class="bitronix.tm.resource.jdbc.PoolingDataSource"> <Set name="className">org.apache.derby.jdbc.EmbeddedXADataSource</Set> <Set name="uniqueName">mydatasource</Set> <Set name="minPoolSize">0</Set> <Set name="maxPoolSize">5</Set> <Get name="driverProperties"> <Put name="databaseName">testdb</Put> <Put name="createDatabase">create</Put> </Get> <Call name="init" /> </New> </Arg> </New> </pre></td></tr></table> <p>The <code>bitronix.tm.resource.jdbc.PoolingDataSource</code> implements <code>javax.sql.DataSource</code> and interacts with the <code>javax.sql.XADataSource</code> provided in this instance by <a href="http://db.apache.org/derby">Derby</a>.</p> <table class="wysiwyg-macro" data-macro-name="tip" data-macro-parameters="title=Hint" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3RpcDp0aXRsZT1IaW50fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>This datasource will be available under this JNDI URL: <strong>java:comp/env/jdbc/mydatasource</strong>.</p></td></tr></table> <p>If your database vendor does not provide an <code>XADataSource</code>, you can use BTM's <code>bitronix.tm.resource.jdbc.lrc.LrcXADataSource</code> as the <code>XADataSource</code> to allow your database connections to be controlled by the transaction manager:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="XML" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6WE1MfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <New id="example-nonxads" class="org.mortbay.jetty.plus.naming.Resource"> <Arg>jdbc/exampleNonXADS</Arg> <Arg> <New class="bitronix.tm.resource.jdbc.PoolingDataSource"> <Set name="className">bitronix.tm.resource.jdbc.lrc.LrcXADataSource</Set> <Set name="uniqueName">exampleNonXADS</Set> <Set name="minPoolSize">0</Set> <Set name="maxPoolSize">5</Set> <Get name="driverProperties"> <Put name="driverClassName">org.apache.derby.jdbc.EmbeddedDriver</Put> <Put name="url">jdbc:derby::example;create=true</Put> </Get> <Call name="init" /> </New> </Arg> </New> </pre></td></tr></table> <table class="wysiwyg-macro" data-macro-name="tip" data-macro-parameters="title=Hint" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3RpcDp0aXRsZT1IaW50fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>This datasource will be available under this JNDI URL: <strong>java:comp/env/jdbc/exampleNonXADS</strong>.</p></td></tr></table> <p>Again, we've used <a href="http://db.apache.org/derby">Derby</a> as an example, but as the <code>LrcXADataSource</code> uses only the class name and url of a <code>java.sql.Driver</code>, you can use it with any database providing a JDBC driver.</p> <h2>Step 4: Configure datasources references in your web.xml</h2> <p>Before your code can access configured datasources via JNDI ENC URLs, you need to declare resource references in your <code>web.xml</code>:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="XML" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6WE1MfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <resource-env-ref> <resource-env-ref-name>jdbc/mydatasource</resource-env-ref-name> <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type> </resource-env-ref> <resource-env-ref> <resource-env-ref-name>jdbc/exampleNonXADS</resource-env-ref-name> <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type> </resource-env-ref> </web-app> </pre></td></tr></table> <p>Now you can perform JNDI lookups on those URLs to access the configured datasources:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> DataSource exampleNonXADS = ctx.lookup("java:comp/env/jdbc/exampleNonXADS"); DataSource mydatasource = ctx.lookup("java:comp/env/jdbc/mydatasource"); </pre></td></tr></table> <p><img class="confluence-embedded-image confluence-external-resource" src="http://www.bitronix.be/images/shim.gif" data-image-src="http://www.bitronix.be/images/shim.gif"></p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced