Using Tomcat as my Servlet Container, how can I deploy two identical wars to different contexts and simply use the context path as the variable which will determine which properties file to load? I'm looking to do something like this in web.xml:
<context-param>
<param-name>initialization.file</param-name>
<param-value>
WEB-INF/config/context${contextPath}.properties
</param-value>
</context-param>
and then load the initialization file based on this context property. Is this possible? If so, how?
I'm using Tomcat 6, Java 6, and Servlet API 2.5.
That depends on what you try to configure. The web.xml is static, no variables can be assigned. But you can pass the variable name where it can be assigned. Implement ServletContextListner and use the ServletContextEvent:
ServletContext servletContext = servletContextEvent.getServletContext();
String contextPath = servletContext.getContextPath();
Than you can replace the variable name with the path and load the properties file. Of course, you need to add the listener to the web.xml, as the very first listener.
It will be loaded at application startup, but keep in mind that you cannot make sure in which order.