Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Context-Scoped JNDI Datasource in Context XML

I'm new to Jetty and am investigating migrating to Jetty 8 from
Tomcat. Our deployment model makes use of JNDI data sources created
and registered via context configuration files. I'm trying to
replicate this setup in Jetty, which by my careful reading of
http://wiki.eclipse.org/Jetty/Feature/JNDI appears to be supported.
Yet I'm getting NameNotFoundException on deployment.

Based on the order of log entries and stepping through the JNDI
components in a debugger, it appears that the EnvConfiguration
component is firing _before_ the JNDI components get
created/registered in the context XML. Moreover, I can't find a
complete example that demonstrates what I'm trying to do. I see
repeated examples of using jetty-env.xml to register context-scoped
entries, but I want to do all context configuration in a single file.

My context XML follows for reference:

<Configure id="cas" class="org.eclipse.jetty.webapp.WebAppContext">

  <Set name="contextPath">/</Set>
  <Set name="war">/home/marvin/apps/cas/cas.war</Set>
  <Call name="setInitParameter">
    <Arg>cas.home</Arg>
    <Arg>/home/marvin/apps/cas</Arg>
  </Call>

  <New id="CASDataSource" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg><Ref id="cas"/></Arg>
    <Arg>jdbc/cas</Arg>
    <Arg>
      <New class="org.apache.tomcat.jdbc.pool.DataSource">
        <Set name="driverClassName">org.postgresql.Driver</Set>
        <Set name="url">${cas.db.url}</Set>
        <Set name="username">${cas.db.username}</Set>
        <Set name="password">${cas.db.password}</Set>
        <Set name="initialSize">2</Set>
        <Set name="maxActive">4</Set>
        <Set name="minIdle">2</Set>
        <Set name="maxWait">5000</Set>
        <Set name="testWhileIdle" type="boolean">true</Set>
        <Set name="testOnBorrow" type="boolean">false</Set>
        <Set name="testOnReturn" type="boolean">false</Set>
        <Set name="validationQuery">SELECT 1</Set>
        <Set name="validationInterval">30000</Set>
        <Set name="timeBetweenEvictionRunsMillis">10000</Set>
        <Set name="minEvictableIdleTimeMillis">600000</Set>
        <Set name="removeAbandoned" type="boolean">true</Set>
        <Set name="jmxEnabled" type="boolean">false</Set>
      </New>
    </Arg>
  </New>

</Configure>

Is there a way to accomplish this? If not, are there alternatives? The
ultimate goal is a deployable that is environment agnostic, which
precludes a /WEB-INF/jetty-env.xml file in the war file.

Thanks,
Marvin


Back to the top