You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tim Watts <ti...@cliftonfarm.org> on 2011/09/22 17:42:37 UTC

[tomcat-6.0.33] META-INF/context.xml Environment not working

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 +"]");
    }
...


Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

Posted by Tim Watts <ti...@cliftonfarm.org>.
Thank you. Good point but basically the same result:

=== EXCEPTION ================================================
javax.servlet.ServletException: Failed initialization
	org.cliftonfarm.xbasic.Controller.init(Controller.java:32)
	javax.servlet.GenericServlet.init(GenericServlet.java:212)
	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:29)
	javax.servlet.GenericServlet.init(GenericServlet.java:212)
...

=== init() ================================================
	@Override
	public void init() throws ServletException {
		super.init();
        // get & store JNDI info
        try {
			configName = InitialContext.doLookup("java:comp/env/configName");
	}
        catch (NamingException e) {
			throw new ServletException("Failed initialization", e);
	}
        log(getClass().getName() +": Successfully initialized. configName=[" +configName +"]");
	}


On Thu, 2011-09-22 at 16:50 +0100, Pid * wrote:
> Why not do your initialisation in the Servlet.init() method?
> 
> 
> p
> 
> On 22 Sep 2011, at 16:42, Tim Watts <ti...@cliftonfarm.org> wrote:
> 
> > 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 +"]");
> >    }
> > ...
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

Posted by Pid * <pi...@pidster.com>.
Why not do your initialisation in the Servlet.init() method?


p

On 22 Sep 2011, at 16:42, Tim Watts <ti...@cliftonfarm.org> wrote:

> 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 +"]");
>    }
> ...
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RE:[OT][tomcat-6.0.33] META-INF/context.xml Environment not working

Posted by Tim Watts <ti...@cliftonfarm.org>.
On Thu, 2011-09-22 at 13:48 -0700, Leo Donahue - PLANDEVX wrote:
> So what is the difference between having a <env-entry> or
> <resource-ref> in web.xml vs. a <Resource> or <Environment> elements
> in META-INF/context.xml?

Well for starters, the web.xml entries will work in all web containers
whereas context.xml is Tomcat-specific.

But the main driver for me is that I want to deliver a .war that I can
drop into ANY web container and have the users configure the app WITHOUT
touching anything in the .war file. I only mentioned the
META-INF/context.xml approach in my original email to simplify the
discussion here. For Tomcat my real aim would be to drop the META-INF
thing and create an equivalent context.xml in
conf/Catalina/${hostname}/${myappcontext}.xml (this is also broke in
6.0.33). Most app servers provide a means of setting JNDI entries via a
web dashboard or a scriptable interface. Tomcat's Manager web interface
used to support this (or maybe it was an extra).

I believe the the Servlet spec says that <env|resource-ref> entries have
to be in web.xml because they tell the container how to expose JNDI
entries to the app in the java:comp/env context. So as 6.0.33 stands, if
I leave them out of web.xml my app works in Tomcat but it's broke
everywhere else. Not good.

I'm trying to see if I can find the problem and so far it's looking like
it might be in org.apache.catalina.startup.ContextConfig but nothing
definite. Not sure how long I'll pursue this. I've got a life to live
and a project to work on.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE:[OT][tomcat-6.0.33] META-INF/context.xml Environment not working

Posted by Leo Donahue - PLANDEVX <Le...@mail.maricopa.gov>.
>-----Original Message-----
>From: Tim Watts [mailto:tim@cliftonfarm.org]
>Subject: RE: [tomcat-6.0.33] META-INF/context.xml Environment not
>working
>
>I got it to work by removing the <env-entry> from web.xml. I believe
>this is a regression because it works correctly under 5.5.17. Under
>5.5.17 it finds the env entry with or without having defined in web.xml.
>Under 6.0.33 having the env entry defined in web.xml *prevents* it from
>finding it.
>

So what is the difference between having a <env-entry> or <resource-ref> in web.xml vs. a <Resource> or <Environment> elements in META-INF/context.xml?

RE: [tomcat-6.0.33] META-INF/context.xml Environment not working

Posted by Tim Watts <ti...@cliftonfarm.org>.
I got it to work by removing the <env-entry> from web.xml. I believe
this is a regression because it works correctly under 5.5.17. Under
5.5.17 it finds the env entry with or without having defined in web.xml.
Under 6.0.33 having the env entry defined in web.xml *prevents* it from
finding it.


On Thu, 2011-09-22 at 09:10 -0700, Leo Donahue - PLANDEVX wrote:
> >-----Original Message-----
> >From: Tim Watts [mailto:tim@cliftonfarm.org]
> >Subject: [tomcat-6.0.33] META-INF/context.xml Environment not working
> >
> >=== 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>
> 
> 
> In my context.xml, I use type="javax.sql.DataSource", and I'm using a <Resource> element instead of <Environment>
> 
>   	<Resource
>         name="configName"
> 		auth="Container"
> 		type="javax.sql.DataSource"
> 		username="username"
> 		password="password"
> 		driverClassName="whatever driver you have"
>             url="your jdbc driver connection stuff"/>
> 
>    	<resource-ref>
>       	<description>DB Connection</description>
>       	<res-ref-name>configName</res-ref-name>
>       	<res-type>javax.sql.DataSource</res-type>
>       	<res-auth>Container</res-auth>
>    	</resource-ref>
> 
> >=== 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>
> 
> 
> I don't have a <env-entry> in my web.xml
> 
> 
> >=== 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 +"]");
> >    }
> >...
> 
> My version of this code, with your name:
> 
>     private DataSource ds;
> 
>     public void createDataSource(){
>         // Setup the DataSource Context
>         try{
>             Context ctx = new InitialContext();
>             ds = (DataSource) ctx.lookup("java:comp/env/configName");
> 
>         } catch (NamingException ex){
>             FacesContext.getCurrentInstance().getExternalContext().log("DataSource lookup failed", ex);
>         }
>     }



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [tomcat-6.0.33] META-INF/context.xml Environment not working

Posted by Leo Donahue - PLANDEVX <Le...@mail.maricopa.gov>.
>-----Original Message-----
>From: Tim Watts [mailto:tim@cliftonfarm.org]
>Subject: [tomcat-6.0.33] META-INF/context.xml Environment not working
>
>=== 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>


In my context.xml, I use type="javax.sql.DataSource", and I'm using a <Resource> element instead of <Environment>

  	<Resource
        name="configName"
		auth="Container"
		type="javax.sql.DataSource"
		username="username"
		password="password"
		driverClassName="whatever driver you have"
            url="your jdbc driver connection stuff"/>

   	<resource-ref>
      	<description>DB Connection</description>
      	<res-ref-name>configName</res-ref-name>
      	<res-type>javax.sql.DataSource</res-type>
      	<res-auth>Container</res-auth>
   	</resource-ref>

>=== 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>


I don't have a <env-entry> in my web.xml


>=== 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 +"]");
>    }
>...

My version of this code, with your name:

    private DataSource ds;

    public void createDataSource(){
        // Setup the DataSource Context
        try{
            Context ctx = new InitialContext();
            ds = (DataSource) ctx.lookup("java:comp/env/configName");

        } catch (NamingException ex){
            FacesContext.getCurrentInstance().getExternalContext().log("DataSource lookup failed", ex);
        }
    }

Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

Posted by Mark Thomas <ma...@apache.org>.
On 23/09/2011 05:37, Tim Watts wrote:
> Wonderful. Thank You!
> 
> You're right about <Parameter>/<context-param> but I'm not sure all
> standards conforming servlet containers are guaranteed to provide an
> 'external override' behaviour.

If the resource entry in web.xml is insufficient to fully configure the
resource, they'll have to provide some form of mechanism for this.

You might also want to read:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#web.xml_configuration
and
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#context.xml_configuration

Mark

> 
> 
> On Fri, 2011-09-23 at 07:07 +0400, Konstantin Kolinko wrote:
>> 2011/9/22 Tim Watts <ti...@cliftonfarm.org>:
>>> 6.0.33
>>
>>>        <Environment
>>>                name="configName"
>>>                value="${catalina.base}/local/xbasic/config/master.properties"
>>>                description="Full path name of the config file."
>>>                type="java.lang.String"/>
>>
>>> I got it to work by removing the <env-entry> from web.xml.
>>
>> You have to add override="false" to your <Environment> element. It is
>> tricky, but it is documented
>>
>> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Environment_Entries
>>
>>
>> BTW, I think <Parameter> (<context-param> in web.xml) are easier to
>> use. Note that it requires override="false" as well.
>>
>> Best regards,
>> Konstantin Kolinko
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

Posted by Tim Watts <ti...@cliftonfarm.org>.
Wonderful. Thank You!

You're right about <Parameter>/<context-param> but I'm not sure all
standards conforming servlet containers are guaranteed to provide an
'external override' behaviour.


On Fri, 2011-09-23 at 07:07 +0400, Konstantin Kolinko wrote:
> 2011/9/22 Tim Watts <ti...@cliftonfarm.org>:
> > 6.0.33
> 
> >        <Environment
> >                name="configName"
> >                value="${catalina.base}/local/xbasic/config/master.properties"
> >                description="Full path name of the config file."
> >                type="java.lang.String"/>
> 
> > I got it to work by removing the <env-entry> from web.xml.
> 
> You have to add override="false" to your <Environment> element. It is
> tricky, but it is documented
> 
> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Environment_Entries
> 
> 
> BTW, I think <Parameter> (<context-param> in web.xml) are easier to
> use. Note that it requires override="false" as well.
> 
> Best regards,
> Konstantin Kolinko
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/9/22 Tim Watts <ti...@cliftonfarm.org>:
> 6.0.33

>        <Environment
>                name="configName"
>                value="${catalina.base}/local/xbasic/config/master.properties"
>                description="Full path name of the config file."
>                type="java.lang.String"/>

> I got it to work by removing the <env-entry> from web.xml.

You have to add override="false" to your <Environment> element. It is
tricky, but it is documented

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Environment_Entries


BTW, I think <Parameter> (<context-param> in web.xml) are easier to
use. Note that it requires override="false" as well.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org