I am having trouble using JNDI when two or more applications are deployed on Tomcat 6.
Consider the following scenario:
I have 2 webapps, where each web.xml contains one JNDI parameter.
web.xml webapp A:
<env-entry>
<env-entry-name>testEntry</env-entry-name>
<env-entry-value>value A</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
web.xml webapp B:
<env-entry>
<env-entry-name>testEntry</env-entry-name>
<env-entry-value>value B</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
When I deploy both webapps and lookup the value for testEntry, both webapps return value A. It seems only the JNDI params from the first loaded web.xml are available. Accoring to my understanding of JNDI, each web.xml contains webapp specific JNDI values that are only available in their own respective context. What am I doing/thinking wrong here?
This leads to my next question. Howto define global JNDI parameters that are available in all contexts? In the tomcat docs I've read that you should use {CATALINA_HOME}/conf/context.xml for this purpose. But the environment entries are not available inside the contexts. Placing them in {CATALINA_HOME}/conf/web.xml makes them globally accessible, but I doubt this is the correct way.
This is my Java code to look them up:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
String value = (String)envCtx.lookup("testEntry");
Any help would be welcome, because good documentation on JNDI is scars.