jetty-env.xml
files should be picked up from WEB-INF/jetty-env.xml automatically, see here: http://www.eclipse.org/jetty/documentation/current/jetty-env-xml.html. I would suggest going with jetty-env.xml
as opposed to jetty-web.xml
.
Can you also show how you are performing the JNDI look up from within your application? Maybe the JNDI datasource is being initialized correctly but the JNDI name isn't correct?
There are some jetty JNDI examples here: http://www.eclipse.org/jetty/documentation/current/jndi-datasource-examples.html
Update: Seems like Jetty won't pick it up automatically when running embedded. Try this:
public static void main(String[] args) throws Exception
{
String jetty_home = "..";
int appli_port = 8080;
Server server = new Server(appli_port);
ProtectionDomain protectionDomain = Loader.class.getProtectionDomain();
URL location = protectionDomain.getCodeSource().getLocation();
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar(location.toExternalForm());
// setup JNDI
EnvConfiguration envConfiguration = new EnvConfiguration();
URL url = new File("path to jetty-env.xml").toURI().toURL();
envConfiguration.setJettyEnvXml(url);
webapp.setConfigurations(new Configuration[] {new WebInfConfiguration(), envConfiguration, new WebXmlConfiguration()});
server.setHandler(webapp);
server.start();
server.join();
}
(See http://blog.armhold.com/2011/12/27/how-to-get-jndi-working-with-wicket-1-5-and-jetty-7-5/)