Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
<resource-ref>
    <description>My DataSource Reference</description>
    <res-ref-name>jdbc/DSTest</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

We will assume that all of the datasources are declared at the jvm scope, but this can be changed as needed.

Don't forget that all JNDI resources can be configured in a jetty.xml file (where they are available to all webapps) or in a WEB-INF/jetty-env.xml file where they will be available only to the declaring webapp. The following xml snippets can be inserted into either , or a context xml file. More information on that can be found here.

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
                 <Set name="driverClass">org.some.Driver</Set>
                 <Set name="jdbcUrl">jdbc.url</Set>
                 <Set name="user">jdbc.user</Set>
                 <Set name="password">jdbc.pass</Set>
     </New>
    </Arg>
   </New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="org.apache.commons.dbcp.BasicDataSource">
                 <Set name="driverClassName">org.some.Driver</Set>
                 <Set name="url">jdbc.url</Set>
                 <Set name="username">jdbc.user</Set>
                 <Set name="password">jdbc.pass</Set>
     </New>
    </Arg>
   </New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
     <Arg></Arg>
     <Arg>jdbc/DSTest</Arg>
     <Arg>
      <New class="com.atomikos.jdbc.AtomikosDataSourceBean">
       <Set name="minPoolSize">2</Set>
       <Set name="maxPoolSize">50</Set>
       <Set name="xaDataSourceClassName">com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</Set>
       <Set name="UniqueResourceName">DSTest</Set>
       <Get name="xaProperties">
         <Call name="setProperty">
           <Arg>url</Arg>
           <Arg>jdbc:mysql://localhost:3306/databasename</Arg>
         </Call>
         <Call name="setProperty">
           <Arg>user</Arg>
           <Arg>some_username</Arg>
         </Call>
         <Call name="setProperty">
           <Arg>password</Arg>
           <Arg>some_password</Arg>
         </Call>
       </Get>
      </New>
     </Arg>
   </New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
                 <Set name="Url">jdbc:mysql://localhost:3306/databasename</Set>
                 <Set name="User">user</Set>
                 <Set name="Password">pass</Set>
     </New>
    </Arg>
   </New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
                 <Set name="User">user</Set>
                 <Set name="Password">pass</Set>
                 <Set name="DatabaseName">dbname</Set>
                 <Set name="ServerName">localhost</Set>
                 <Set name="PortNumber">1433</Set>

     </New>
    </Arg>
   </New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
                 <Set name="URL">jdbc:oracle:thin:@localhost:1521:orcl</Set>
                 <Set name="User">user</Set>
                 <Set name="Password">pass</Set>

     </New>
    </Arg>
</New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="org.postgresql.ds.PGSimpleDataSource">
                 <Set name="User">user</Set>
                 <Set name="Password">pass</Set>
                 <Set name="DatabaseName">dbname</Set>
                 <Set name="ServerName">localhost</Set>
                 <Set name="PortNumber">5432</Set>

     </New>
    </Arg>
   </New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="org.postgresql.ds.PGConnectionPoolDataSource">
                 <Set name="User">user</Set>
                 <Set name="Password">pass</Set>
                 <Set name="DatabaseName">dbname</Set>
                 <Set name="ServerName">localhost</Set>
                 <Set name="PortNumber">5432</Set>

     </New>
    </Arg>
   </New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="com.sybase.jdbc2.jdbc.SybDataSource">
                 <Set name="DatabaseName">dbname</Set>
                 <Set name="User">user</Set>
                 <Set name="Password">pass</Set>
                 <Set name="ServerName">servername</Set>
                 <Set name="PortNumber">5000</Set>

     </New>
    </Arg>
</New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="com.ibm.db2.jcc.DB2SimpleDataSource">
                 <Set name="DatabaseName">dbname</Set>
                 <Set name="User">user</Set>
                 <Set name="Password">pass</Set>
                 <Set name="ServerName">servername</Set>
                 <Set name="PortNumber">50000</Set>

     </New>
    </Arg>
</New>

...

Code Block
xml
xml
<New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
     <New class="com.ibm.db2.jcc.DB2ConnectionPoolDataSource">
                 <Set name="DatabaseName">dbname</Set>
                 <Set name="User">user</Set>
                 <Set name="Password">pass</Set>
                 <Set name="ServerName">servername</Set>
                 <Set name="PortNumber">50000</Set>

     </New>
    </Arg>
</New>
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery