I have the following:
Startup code:
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setDescriptor("/WEB-INF/web.xml");
context.setResourceBase("/home/webapp);
context.setContextPath("/");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
jetty-env.xml in /home/webapp/WEB-INF:
<?xml version="1.0"?>
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="properties" class="org.mortbay.jetty.plus.naming.EnvEntry">
<Arg>property_file</Arg>
<Arg>/home/webapp/web.properties</Arg>
</New>
</Configure>
jndi.properties in classpath:
java.naming.factory.url.pkgs=org.eclipse.jetty.jndi
java.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory
The initial context is created OK, but attempting to lookup the property_file key throws name not found exception. Enumeration only returns the keys defined in jndi.properties.
Context initContext = new InitialContext();
Hashtable<?,?> ht = initContext.getEnvironment();
Enumeration<?> keys = ht.keys();
while(keys.hasMoreElements()) {
Object key = keys.nextElement();
System.out.println(key.toString() + "=" + ht.get(key).toString());
}
String props=(String)initContext.lookup("java:comp/env/property_file");
What am I doing wrong?