You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kishanthan Thangarajah <ks...@gmail.com> on 2012/02/28 13:31:31 UTC

Embedded tomcat does not read webapp specific context.xml

Hi,
I'm using embedded tomcat(7.0.14) in one of my application. I have extended
Tomcat class and used that to add webapps by calling the addWebapp
method. Everything works accordingly. But this way, if a webapp contains a
context.xml(META-INF/context.xml) within, it is not getting read by
embedded tomcat.

Then after some investigation i found the following to set the contextXml
file programmatically.
According to the API documentation, addWebapp method returns the Context
for the added webapp [1]. So what i did later is, i used this Context to
set the contextXml file by calling setConfigFile method. But still i'm
unable to get tomcat to read webapp specific context files.

In Both occasions, the error i'm getting is,

javax.naming.NamingException: Cannot create resource instance
at
org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:117)
 at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:826)
 at org.apache.naming.NamingContext.lookup(NamingContext.java:145)
at org.apache.naming.NamingContext.lookup(NamingContext.java:814)
 at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.kishan.j2ee.sample.servlet.MyServlet.doGet(MyServlet.java:49)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

What i'm trying to achieve is defining webapp specific resources in the
contextXml file and use them in the respective webapps.

So what would be the correct way to get embedded tomcat to load the
contextXml file specific to webapps?

Thanks,
Kishanthan.

[1] http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/startup/Tomcat.html#addWebapp(java.lang.String,
java.lang.String)