In my conf/server.xml I define: <Environment name="test" type="java.lang.String" value="hello world"/> Then in my webapp/WEB-INF/web.xml I add: <resource-env-ref> <description>test</description> <resource-env-ref-name>test</resource-env-ref-name> <resource-env-ref-type>java.lang.String</resource-env-ref-type> </resource-env-ref> Then from a servlet I use code such as: InitialContext initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); String hello = (String)envCtx.lookup("test"); I tried all manner of variations to try to make it work and eventually ended up downloading the source, debugging tomcat and seeing that the ResourceEnvRef is registered incorrectly as follows: 15:02:06,809 DEBUG [NamingContextListener] Adding resource env ref /Catalina/localhost/router-web Reviewing the source (HEAD as of 15-dec-2004), it looks like the code is in fact using the wrong name to register the resource: NamingContextListener, line 855: /** * Set the specified resources in the naming context. */ public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) { // Create a reference to the resource env. Reference ref = new ResourceEnvRef(resourceEnvRef.getType()); // FIXME: Adding the additional parameters, if any Iterator params = resourceEnvRef.listProperties(); while (params.hasNext()) { String paramName = (String) params.next(); String paramValue = (String) resourceEnvRef.getProperty(paramName); StringRefAddr refAddr = new StringRefAddr(paramName, paramValue); ref.add(refAddr); } try { if (logger.isDebugEnabled()) log.debug(" Adding resource env ref " + name); createSubcontexts(envCtx, name); envCtx.bind(name, ref); ^^^^^^^ "name" is an attribute of the containing class, NamingContextListener. This seems wrong. It should be registered under a name obtained from the resource- env-entry (resourceEnvRef object). Hope this helps somebody out there.
I suppose this was caused by a cut & paste error. Thanks.