title: JNDI lookup failed (NameNotFoundException)
body: <p><strong>UPDATE</strong>: Well, it seems that this is a problem only when I try to debug locally. When published on Jetty (not the same machine) it works great. Is it possible to configure the jetty.xml file used by Run-Jetty-Run when debugging locally?</p>
  
  <p>I just wasted an afternoon trying to find the cause of this, but with no success...</p>
  
  <p>I'm setting up a connection pool with c3p0 for my application. I'm using Jetty 7, by the way. The problem is that when I do a context.lookup get a datasource, I get this exception:</p>
  
  <pre><code>javax.naming.NameNotFoundException; remaining name 'env/jdbc/DSTest'
  at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:634)
  at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:665)
  at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:680)
  at org.eclipse.jetty.jndi.java.javaRootURLContext.lookup(javaRootURLContext.java:113)
  at javax.naming.InitialContext.lookup(InitialContext.java:392)
  at com.see.metrics.SqlHelper.Initialize(SqlHelper.java:68)
  at com.see.metrics.Metrics.Initialize(Metrics.java:45)
  at com.see.game.GameProducer.generateMetadata(GameProducer.java:223)
  at org.odata4j.producer.mongodb.MongoProducer.initMongo(MongoProducer.java:98)
  at org.odata4j.producer.mongodb.MongoProducerFactory.create(MongoProducerFactory.java:55)
  at org.odata4j.producer.resources.ODataProducerProvider.newProducerFromFactory(ODataProducerProvider.java:66)
  at org.odata4j.producer.resources.ODataProducerProvider.getInstance(ODataProducerProvider.java:48)
  at org.odata4j.producer.resources.ODataProducerProvider.getInstance(ODataProducerProvider.java:1)
  at com.sun.jersey.core.impl.provider.xml.LazySingletonContextProvider.get(LazySingletonContextProvider.java:80)
  at com.sun.jersey.core.impl.provider.xml.LazySingletonContextProvider.access$000(LazySingletonContextProvider.java:52)
  at com.sun.jersey.core.impl.provider.xml.LazySingletonContextProvider$1.getValue(LazySingletonContextProvider.java:69)
  at com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable$1.getValue(AbstractHttpContextInjectable.java:100)
  at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:43)
  at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:119)
  at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:166)
  at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
  at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:259)
  at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
  at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
  at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)
  at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:990)
  at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
  at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
  at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
  at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
  at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
  at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:478)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
  at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
  at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
  at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
  at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
  at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
  at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
  at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
  at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
  at org.eclipse.jetty.server.Server.handle(Server.java:346)
  at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
  at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1048)
  at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601)
  at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
  at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
  at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
  at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
  at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
  at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>I have a <strong>jndi.properties</strong> file to configure my InitialContext (located in my resource folder src/main/resources)</p>
  
  <pre><code>java.naming.factory.url.pkgs=org.eclipse.jetty.jndi
  java.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory
  </code></pre>
  
  <p>I also have a <strong>jetty-env.xml</strong> file in the webapp/WEB-INF folder:</p>
  
  <pre><code>&lt;Configure class="org.mortbay.jetty.webapp.WebAppContext"&gt;
  
  &lt;!--&lt;Set name="ConfigurationClasses"&gt;
     &lt;Ref id="plusConfig"/&gt;
  &lt;/Set&gt;  --&gt;
  
  &lt;!-- MySql datasource org.eclipse.jetty.plus.jndi.Resource Factory--&gt;
  &lt;New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource"&gt;
      &lt;Arg&gt;&lt;/Arg&gt;
      &lt;Arg&gt;jdbc/DSTest&lt;/Arg&gt;
      &lt;Arg&gt;
       &lt;New class="com.mchange.v2.c3p0.ComboPooledDataSource"&gt;
          &lt;Set name="driverClassName"&gt;com.mysql.jdbc.Driver&lt;/Set&gt;
          &lt;Set name="url"&gt;jdbc:mysql://host/&lt;/Set&gt;
          &lt;Set name="username"&gt;username&lt;/Set&gt;
          &lt;Set name="password"&gt;password&lt;/Set&gt;
          &lt;Set name="checkoutTimeout"&gt;5000&lt;/Set&gt;
          &lt;Set name="initialPoolSize"&gt;10&lt;/Set&gt;
          &lt;Set name="maxIdleTime"&gt;30&lt;/Set&gt;
          &lt;Set name="maxPoolSize"&gt;160&lt;/Set&gt;
          &lt;Set name="minPoolSize"&gt;10&lt;/Set&gt;
          &lt;Set name="maxStatements"&gt;200&lt;/Set&gt;
          &lt;Set name="maxConnectionAge"&gt;0&lt;/Set&gt;
          &lt;Set name="acquireIncrement"&gt;15&lt;/Set&gt;
      &lt;/New&gt;
    &lt;/Arg&gt;
   &lt;/New&gt;
  &lt;/Configure&gt;
  </code></pre>
  
  <p>And I added those lines in my <strong>web.xml</strong> file:</p>
  
  <pre><code>&lt;resource-ref&gt;
    &lt;description&gt;DB Connection&lt;/description&gt;
    &lt;res-ref-name&gt;jdbc/DSTest&lt;/res-ref-name&gt;
    &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
    &lt;res-auth&gt;Container&lt;/res-auth&gt;
  &lt;/resource-ref&gt;
  </code></pre>
  
  <p>I seem to have followed all the required steps, but I still get a javax.naming.NameNotFoundException when doing the lookup...</p>
  
  <p>Any hints?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong>:
  I forgot to put how I do my lookup.</p>
  
  <pre><code>InitialContext ctx = new InitialContext();
  DataSource dataSource = (DataSource)ctx.lookup("java:comp/env/jdbc/DSTest");
  </code></pre>