Versions Compared

Key

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

...

What can be bound and general overview

There are 3 4 types of objects that can be bound into Jetty's JNDI:

The binding for all of these object types generally follows the same pattern:

...

  • "org.mortbay.jetty.plus.naming.EnvEntry" for <env-entry>s
  • "org.mortbay.naming.plus.Resource" for all other type of resources
  • "org.mortbay.plus.naming.Transaction" for a JTA manager. We'll take a closer look at this in the Configuring XA Transactions section).
  • "org.mortbay.plus.naming.Link" for link between a web.xml resource name and a NamingEntry. See Configuring Links for more info.

There are 3 places in which you can define naming entries:

...

See also the instructions for how to configure JOTM. Contributions of instructions for other transaction managers are welcome.

Anchor
links
links

Usually, the name you configure for your NamingEntry should be the same as the name you refer to it as in you web.xml. For example:

Code Block
xml
xml

In a context xml file:

<Configure id='wac' class="org.mortbay.jetty.webapp.WebAppContext">
...
<New id="myds" class="org.mortbay.jetty.plus.naming.Resource">
  <Arg><Ref id="wac"/></Arg>
  <Arg>jdbc/mydatasource</Arg>
  <Arg>
    <New class="org.apache.derby.jdbc.EmbeddedDataSource">
      <Set name="DatabaseName">test</Set>
      <Set name="createDatabase">create</Set>
    </New>
  </Arg>
</New>
</Configure>

and in web.xml:

  <resource-ref>
    <res-ref-name>jdbc/mydatasource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <injection-target>
      <injection-target-class>com.acme.JNDITest</injection-target-class>
      <injection-target-name>myDatasource</injection-target-name>
    </injection-target>
  </resource-ref>

If you wish, you can refer to it in web.xml by a different name, and link it to the name in your org.mortbay.jetty.plus.naming.Resource by using an org.mortbay.jetty.plus.naming.Link type of NamingEntry. For the example above, we could refer to the jdbc/mydatasource resource as {{jdbc/mydatasource1}
by doing:

Code Block
xml
xml

In a context xml file:

<Configure id='wac' class="org.mortbay.jetty.webapp.WebAppContext">
...
<New id="myds" class="org.mortbay.jetty.plus.naming.Resource">
  <Arg><Ref id="wac"/></Arg>
  <Arg>jdbc/mydatasource</Arg>
  <Arg>
    <New class="org.apache.derby.jdbc.EmbeddedDataSource">
      <Set name="DatabaseName">test</Set>
      <Set name="createDatabase">create</Set>
    </New>
  </Arg>
</New>
</Configure>


in a jetty-env.xml file:

  <New id="map1" class="org.mortbay.jetty.plus.naming.Link">
    <Arg><Ref id='wac'/></Arg>
    <Arg>jdbc/mydatasource1</Arg> <!-- name in web.xml -->
    <Arg>jdbc/mydatasource</Arg>  <!-- name in container environment -->
  </New>


and in web.xml:

  <resource-ref>
    <res-ref-name>jdbc/mydatasource1</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <injection-target>
      <injection-target-class>com.acme.JNDITest</injection-target-class>
      <injection-target-name>myDatasource</injection-target-name>
    </injection-target>
  </resource-ref>

This can be useful when you cannot change web.xml but need to link it to a resource in your deployment environment.

Global or scoped to a webapp

...

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