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

googley
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
        ....
        <build>
                <finalName>WebAppA</finalName>
                <plugins>
                       ....
                        <plugin>
                                <groupId>org.mortbay.jetty</groupId>
                                <artifactId>maven-jetty-plugin</artifactId>
                                <version>6.1.22</version>
                                <configuration>
                                        <scanIntervalSeconds>10</scanIntervalSeconds>
                                        <contextPath>/WebAppA</contextPath>
                                        <jettyConfig>${basedir}/jetty.xml</jettyConfig>
                                </configuration>
                        </plugin>
                </plugins>
        </build>
        ....

Jetty Config

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

<New id="jdbcDS" class="org.mortbay.jetty.plus.naming.Resource">
        <Arg></Arg>
        <Arg>jdbc/Foo</Arg>
        <Arg>
                <New class="oracle.jdbc.pool.OracleDataSource">
                        <Set name="URL">jdbc:oracle:thin:@127.0.0.1:1521:XE</Set>
                        <Set name="user">foo</Set>
                        <Set name="password">foo</Set>
                </New>
        </Arg>
</New>

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

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

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

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(NamingContext.java:578)
        at org.mortbay.naming.NamingContext.lookup(NamingContext.java:665)
        at org.mortbay.naming.NamingContext.lookup(NamingContext.java:680)
        at org.mortbay.naming.java.javaRootURLContext.lookup(javaRootURLContext.java:112)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at foo.FooBean.doReadData(FooBean.java:17)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
        at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
        at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
        ... 32 more