Hello,
My very basic servlet fails to initialize when trying to read its JNDI
environment entry. The app context name is xbasic. The context.xml is in
xbasic.war's META-INF directory and TomCat (6.0.33) correctly copies it
to ${tomcat.home}/conf/Catalina/localhost/xbasic.xml on first deploy.
Below are the relevant snippets. Can anyone see what I'm doing wrong or
is this a bug?
BTW, I'm running this under openjdk 6.
=== EXCEPTION ================================================
javax.servlet.ServletException: Error instantiating servlet class
org.cliftonfarm.xbasic.Controller
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:636)
root cause
javax.naming.NameNotFoundException: Name configName is not bound in this Context
org.apache.naming.NamingContext.lookup(NamingContext.java:770)
org.apache.naming.NamingContext.lookup(NamingContext.java:140)
org.apache.naming.NamingContext.lookup(NamingContext.java:781)
org.apache.naming.NamingContext.lookup(NamingContext.java:140)
org.apache.naming.NamingContext.lookup(NamingContext.java:781)
org.apache.naming.NamingContext.lookup(NamingContext.java:153)
org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
javax.naming.InitialContext.lookup(InitialContext.java:409)
javax.naming.InitialContext.doLookup(InitialContext.java:282)
org.cliftonfarm.xbasic.Controller.<init>(Controller.java:28)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
=== context.xml ================================================
<Context unpackWAR="false" privileged="false" antiResourceLocking="false"
antiJARLocking="false">
<Environment
name="configName"
value="${catalina.base}/local/xbasic/config/master.properties"
description="Full path name of the config file."
type="java.lang.String"/>
</Context>
=== web.xml ================================================
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>org.cliftonfarm.xbasic.Controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<env-entry>
<env-entry-name>configName</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
</web-app>
=== Servlet constructor ========================================
public class Controller extends HttpServlet {
private static final long serialVersionUID = 1L;
private String configName;
/**
* @throws NamingException
* @see HttpServlet#HttpServlet()
*/
public Controller() throws NamingException {
super();
// get & store JNDI info
configName = InitialContext.doLookup("java:comp/env/configName"); //
line 28
log(getClass().getName() +": Successfully initialized. configName=["
+configName +"]");
}
...