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


<Array id="plusConfig" type="java.lang.String">
  <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
  <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
  <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
  <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
  <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>     <!-- add for jndi -->
  <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>    <!-- add for jndi -->
  <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
</Array>

        

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. The file also contains other (commented out) alternatives for enabling JNDI with webapps, such as creating a separate deployer just for deploying JNDI-enabled webapps.

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:


<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
  <Array id="plusConfig" type="java.lang.String">
    <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
    <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
    <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
    <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
    <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>     <!-- add for JNDI -->
    <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>    <!-- add for JNDI -->
    <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
  </Array>

  <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/my-cool-webapp</Set>
  <Set name="configurationClasses"><Ref refid="plusConfig"/></Set>
</Configure>

        

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):

  
  <!-- =========================================================== -->
  <!-- Apply plusConfig to all webapps in webapps-plus             -->
  <!-- =========================================================== -->
  <!-- Uncomment the following to set up a deployer that will      -->
  <!-- deploy webapps from a directory called webapps-plus. Note   -->
  <!-- that you will need to create this directory first!          -->
  <Ref refid="DeploymentManager">
      <Call name="addAppProvider">
        <Arg>
          <New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
            <Set name="monitoredDirName"><Property name="jetty.home" default="." />/webapps-plus</Set>
            <Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
            <Set name="scanInterval">5</Set>
            <Set name="parentLoaderPriority">false</Set>
            <Set name="extractWars">true</Set>
            <Set name="configurationClasses"><Ref refid="plusConfig"/></Set>
          </New>
        </Arg>
      </Call>
  </Ref>

        

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 the plus OPTION on the command line so it is valid for that run only. Here's how to do it:


$ java -jar start.jar OPTIONS=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=plus etc/jetty-plus.xml

        

See an error or something missing? Contribute to this documentation at Github!