global JNDI DataSource not working for multiple webapps in jetty.xml

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

global JNDI DataSource not working for multiple webapps in jetty.xml

I am deploying a web application A using the maven jetty plugin (hot deploy). It in turn depends on web application B being deployed (static deploy). Both web applications share a common JNDI DataSource. I have configured a global DataSource in jetty.xml but the problem is that I get a javax naming exception in web app B (web app A is OK - both apps share the same JNDI lookup code).

I there something with my jetty configuration? Or can anyone suggest an alternative configuration for the above scenario?

Thanks in advance.

Web App A POM

Jetty Config

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "">
<Configure id="Server" class="org.mortbay.jetty.Server">

<New id="jdbcDS" class="">
                <New class="oracle.jdbc.pool.OracleDataSource">
                        <Set name="URL">jdbc:oracle:thin:@</Set>
                        <Set name="user">foo</Set>
                        <Set name="password">foo</Set>

    <Set name="handler">
        <New id="Handlers"
            <Set name="handlers">
                <Array type="org.mortbay.jetty.Handler">
                        <New id="WebHandler"
                            class="org.mortbay.jetty.webapp.WebAppContext" />
    <Ref id="WebHandler">
        <Set name="contextPath">/WebAppB</Set>
        <Set name="war">../WebAppB/target/WebAppB.war</Set>

resource-ref section of WEB.XML for both web apps

                <description>DB Connection</description>

JNDI lookup code in both web apps

                Context ctx = new InitialContext();
                ctx = (Context)ctx.lookup("java:comp/env");
                DataSource ds = (DataSource)ctx.lookup("jdbc/Foo");
                Connection con = ds.getConnection();

Naming Exception for Web app B (note that Web App is OK with same JNDI lookup code)

Caused by: javax.naming.NameNotFoundException; remaining name 'env'
        at org.mortbay.naming.NamingContext.lookup(
        at org.mortbay.naming.NamingContext.lookup(
        at org.mortbay.naming.NamingContext.lookup(
        at javax.naming.InitialContext.lookup(
        at foo.FooBean.doReadData(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at com.sun.el.parser.AstValue.invoke(
        at com.sun.el.MethodExpressionImpl.invoke(
        at com.sun.facelets.el.TagMethodExpression.invoke(
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(
        ... 32 more