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?
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:
- jetty.xml
- WEB-INF/jetty-env.xml
- 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 ajetty-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 ajetty.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With