Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused about jetty-env.xml

I have a webapp that uses JNDI to locate a datasource and a transaction manager. I see from the Jetty documentation how to do this via the jetty-env.xml file. However it mentions that this file should be put into the WEB-INF directory.

Why would they suggest that JNDI resources be configured in a configuration file that is located inside my WAR? It makes no sense...I always thought of JNDI as a way to externalize configuration. Is there another place I can put this file on a Jetty server machine?

A follow up question: How about within my Maven WAR module...how should I deal with this file so that I can use the Maven jetty plugin for development, but not have the file end up in the WAR?

like image 742
HDave Avatar asked Oct 12 '10 20:10

HDave


1 Answers

Is there another place I can put this file on a Jetty server machine?

The official JNDI page puts it like this:

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

  1. jetty.xml
  2. WEB-INF/jetty-env.xml
  3. context xml file

Naming entries defined in a jetty.xml file will generally be scoped at either the jvm level or the Server level. Naming entries in a jetty-env.xml file will generally be scoped to the webapp in which the file resides, although you are able to enter jvm or Server scopes if you wish, that is not really recommended. In most cases you will define all naming entries that you want visible to a particular Server instance, or to the jvm as a whole in a jetty.xml file. Entries in a context xml file will generally be scoped at the level of the webapp to which it applies, although once again, you can supply a less strict scoping level of Server or jvm if you want.

Use jetty.xml to configure things "outside" the webapp.

A follow up question: How about within my Maven WAR module...how should I deal with this file so that I can use the Maven jetty plugin for development, but not have the file end up in the WAR?

Use the jettyConfig parameter of the Maven Jetty Plugin:

jettyConfig Optional. The location of a jetty.xml file that will be applied in addition to any plugin configuration parameters. You might use it if you have other webapps, handlers etc to be deployed, or you have other jetty objects that cannot be configured from the plugin.

like image 57
Pascal Thivent Avatar answered Sep 28 '22 17:09

Pascal Thivent