>-----Original Message-----
>From: Tim Watts [mailto:t...@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);
        }
    }

Reply via email to