Tomcat6 ignores META-INF/context.xml

context.xmljnditomcat

Tomcat6 keeps ignoring my META-INF/context.xml. I keep getting "Name tt is not bound in this Context" when I try to look up "tt" (please see 'details').

When I put the content of META-INF/context.xml inside the 'context' tag in server.xml, it works. I've also checked that $Tomcat-base/Catalina/localhost is empty, so my META-INF/context.xml is not overridden.


details:

Tomcat version: 6.0.10

Here's my Webroot structure:

Webroot
       |-META-INF
       |      |-context.xml
       |
       |-WEB-INF
             |-web.xml

Content of context.xml:

<Context>
    <Environment name="tt" value="this is a string" type="java.lang.String"></Environment>
</Context>

Context tag of this webroot in server.xml:

<Context path="/test" docBase="E:\javaProjects\TestProject\Webroot" reloadable="true"></Context>

The way I look up for "tt":

...
Context ic = new InitialContext();
Context ec = (Context) ic.lookup("java:comp/env");
String str = (String) ec.lookup("tt");
System.out.println("str is "+str);

The error I get:

javax.naming.NameNotFoundException: Name tt is not bound in this context

Best Answer

I've got your code working IF I delete the <Context> from the server.xml and define it only in the META-INF/context.xml

It doesn't work when the <Context> is defined in both places.

Secondly, change your type to String, instead of Integer

<Environment name="tt" value="this is a string" type="java.lang.String"></Environment>
</Context>
Related Topic