Jetty Logo
Version: 9.2.7-SNAPSHOT
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

Working with Jetty JNDI

Defining the web.xml
Declaring Resources
Deciding Where to Declare Resources
Scope of Resource Names
What Can Be Bound as a Resource?

Defining the web.xml

You can configure naming resources to reference in a web.xml file and access from within the java:comp/env naming environment of the webapp during execution. Specifically, you can configure support for the following web.xml elements:

Configuring env-entries shows you how to set up overrides for env-entry elements in web.xml, while Configuring resource-refs and resource-env-refs discusses how to configure support resources such as javax.sql.DataSource.

You can also plug a JTA javax.transaction.UserTransaction implementation into Jetty so that webapps can look up java:comp/UserTransaction to obtain a distributed transaction manager: see Configuring XA Transactions.

Declaring Resources

You must declare the objects you want bound into the Jetty environment so that you can then hook into your webapp via env-entry, resource-ref and resource-env-refs in web.xml. You create these bindings by using declarations of the following types:

org.eclipse.jetty.plus.jndi.EnvEntry

for env-entry type of entries

org.eclipse.jetty.plus.jndi.Resource

for all other type of resources

org.eclipse.jetty.plus.jndi.Transaction

for a JTA manager

org.eclipse.jetty.plus.jndi.Link

for link between a web.xml resource name and a naming entry

Declarations of each of these types follow the same general pattern:

You can place these declarations into three different files, depending on your needs and the scope of the resources being declared.

Deciding Where to Declare Resources

You can define naming resources in three places:

jetty.xml

Naming resources defined in a jetty.xml file are scoped at either the JVM level or the Server level. The classes for the resource must be visible at the Jetty container level. If the classes for the resource only exist inside your webapp, you must declare it in a WEB-INF/jetty-env.xml file.

WEB-INF/jetty-env.xml

Naming resources in a WEB-INF/jetty-env.xml file are scoped to the web app in which the file resides. While you can enter JVM or Server scopes if you choose, we do not recommend doing so. The resources defined here may use classes from inside your webapp. This is a Jetty-specific mechanism.

context xml file

Entries in a context xml file should be scoped at the level of the webapp to which they apply, although you can supply a less strict scoping level of Server or JVM if you choose. As with resources declared in a jetty.xml file, classes associated with the resource must be visible on the container's classpath.

Scope of Resource Names

Naming resources within Jetty belong to one of three different scopes, in increasing order of restrictiveness:

JVM scope

The name is unique across the JVM instance, and is visible to all application code. You represent this scope by a null first parameter to the resource declaration. For example:

Server scope

The name is unique to a Server instance, and is only visible to code associated with that instance. You represent this scope by referencing the Server instance as the first parameter to the resource declaration. For example:

Webapp scope

The name is unique to the WebAppContext instance, and is only visible to code associated with that instance. You represent this scope by referencing the WebAppContext instance as the first parameter to the resource declaration. For example:

What Can Be Bound as a Resource?

You can bind four types of objects into a Jetty JNDI reference:

See an error or something missing? Contribute to this documentation at Github!(Generated: 2014-12-21T01:00:26-08:00)