Search code examples
javarestjettyjax-rsjndi

Jetty JNDI with Oracle error: IllegalStateException: Nothing to bind for name jdbc/replaydev


I have written a JAX-RS REST-API, that fetches rows from Oracle.
For this I have used JNDI since I am using Jetty. But on deploying the WAR file I am getting the following error:

Caused by:
java.lang.IllegalStateException: Nothing to bind for name jdbc/replaydev
        at org.eclipse.jetty.plus.webapp.PlusDescriptorProcessor.bindEntry(PlusDescriptorProcessor.java:914)

My web.xml has the following entry:

<resource-ref>
 <res-ref-name>jdbc/replaydev</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
</resource-ref>

WEB-INF/jetty-env.xml has following entries:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"    "http://www.eclipse.org/jetty/configure_9_0.dtd">

<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
  <New id="replaydev" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg><Ref refid='wac'/></Arg>
    <Arg>jdbc/replaydev</Arg>
    <Arg>
      <New class="oracle.jdbc.pool.OracleDataSource">
        <Set name="URL">jdbc:oracle:thin://@MY.ORACLE.SERVER:1555/JOBCTL</Set>
        <Set name="User">XYZ</Set>
        <Set name="Password">rockOn</Set>
        <Set name="connectionCachingEnabled">true</Set>
      </New>
    </Arg>
  </New> 
</Configure>

And my Java code has the following:

Context initContext = new InitialContext();
ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/replaydev");

con = ds.getConnection();
Class.forName("oracle.jdbc.OracleDriver");

POM.xml has following dependencies added:

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-server</artifactId>
    <version>9.2.11.v20150529</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-webapp</artifactId>
    <version>9.2.11.v20150529</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-plus</artifactId>
    <version>9.2.11.v20150529</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-jndi</artifactId>
    <version>9.2.11.v20150529</version>
</dependency>

I even tried adding id tags in web.xml entry like: <resource-ref id="replaydev">....</resource-ref> for jetty-env.xml <New id="replaydev" class="org.eclipse.jetty.plus.jndi.Resource">. Its not working either.

Am I missing something??


Solution

  • Thanks @voodoo14 and @joakim.
    I found the soultion. I actually removed the dependencies shown above in the POM.xml
    This is because I already had a standalone jetty v9 running. And I believe that the dependencies mentioned above are creating one more jetty within.
    So I removed the dependencies and things worked.