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

Detailed Setup

Setting Up the List of Configurations
Enabling JNDI for a Single WebApp
Enabling JNDI for a Deployer
Adding JNDI Implementation Jars to the Jetty Classpath

The following sections describe the finer points of configuring JNDI in Jetty.

Setting Up the List of Configurations

When deploying a webapp, Jetty has an extensible list of configurations that it applies to the webapp in a specific order. These configurations do things like parse the web.xml, set up the classpath for the webapp, and parse jetty specific WEB-INF/jetty-web.xml files.

To use JNDI with Jetty, you need additional attributes that do things like read WEB-INF/jetty-env.xml, set up a java:comp/env context, and hook up JNDI entries from the environment into your webapp. The list below shows the two extra elements and the order you must use when you add them:

This augmented list of configurations for JNDI is predefined for you in the etc/jetty-plus.xml file:

The Quick Setup section shows you how to enable it. Be aware that the etc/jetty-plus.xml file enables JNDI for all webapps for a given Server instance.

Now skip down to Adding JNDI Implementation Jars to the Jetty Classpath if you want to use JNDI with all webapps. If you only want to use JNDI with specific webapps, read on.

Enabling JNDI for a Single WebApp

If you have only a few webapps that you want to use with JNDI, you can apply the augmented list of configurations specifically to those webapps. To do that, create a context XML file for each webapp, and set up the configuration classes. Here's an example of how that should look:

Enabling JNDI for a Deployer

Another alternative to enabling JNDI for all webapps (see Quick Setup, or just individual webapps (see Enabling JNDI for a Single WebApp) is to create a specific Deployer instance that enables JNDI for all weabpps it deploys. That way, you can set up the configurations once to apply them to every webapp you drop into the nominated directory738211;in this way you keep your JNDI-enabled webapps separate from the non-JNDI enabled webapps. The etc/jetty-plus.xml file has an example of this (commented out):

This creates a new deployer that looks for things to deploy in the webapps-plus directory and sets up the JNDI configurations for them.

Note

If you do this, you need to either supply the etc/jetty-plus.xml file last on the runline, or move it to after the etc/jetty-deploy.xml file reference in start.ini. This is because this section of the etc/jetty-plus.xml file refers to the DeploymentManager, which is created in the etc/jetty-deploy.xm file.

Adding JNDI Implementation Jars to the Jetty Classpath

Now that you have the JNDI configuration for the webapp/s set up, you need to ensure that the JNDI implementation Jars are on the Jetty classpath. These jars are optional, so are not there by default. You add these into the classpath by using startup time OPTIONS.

In the Quick Setup section, we showed you how to use start.ini to accomplish this in a permanent fashion. Instead, you can supply OPTION on the command line so it is valid for that run only. Here's how to do it:


$ java -jar start.jar OPTIONS=jndi,plus

        

Be aware that if you haven't set up the configurations that enable JNDI for individual webapps, you need to use the etc/jetty-plus.xml file, which you can also do on the runline:


$ java -jar start.jar OPTIONS=jndi,plus etc/jetty-plus.xml

        

See an error or something missing? Contribute to this documentation at Github!(Generated: 2014-09-18T01:00:27-07:00)