JNDI binding in JBoss

How to get a JNDI name in a DSdotXML file (-ds.xml) with a matching application reference in JBoss. Thanks to Ketan, who is awesome!

I had big problems getting this to work. I wrote about in the Adobe LiveCycle Developers Google Group: Problem with JNDI binding in JBoss (LiveCycle turnkey) and on StackOverflow: Problem with JNDI binding in JBoss (LiveCycle turnkey), but it was my friend Ketan who pointed out the solution.

I needed a jboss-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
   <resource-ref>
      <res-ref-name>RMB_DS</res-ref-name>
      <jndi-name>java:/RMB_DS</jndi-name>
   </resource-ref>
</jboss-web>

And changed the original web.xml to have:

<resource-ref>
   <description>DB Connection</description>
   <res-ref-name>RMB_DS</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>

Which matches rmb-ds.xml

<datasources>
   <local-tx-datasource>
      <jndi-name>RMB_DS</jndi-name>
      <connection-url>jdbc:sqlserver://localhost\SQLEXPRESS;DatabaseName=RMB</connection-url>
      <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
      <user-name>sa</user-name>
      <password>password</password>
      <check-valid-connection-sql>SELECT 1 FROM sysobjects</check-valid-connection-sql>
      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
      <metadata>
         <type-mapping>MS SQLSERVER2000</type-mapping>
      </metadata>
   </local-tx-datasource>
</datasources>

Popular Posts