Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] NameNotFoundException on JNDI lookup

resource-ref in web.xml is typically the most portable way to wire a jndi resource into a webapp, jetty-env.xml typically lets you wire in jetty specific container configuration for declaring that jndi resource inside of the webapp....personally I prefer not seeing jetty-env.xml in a webapp and let the container configure it in a context.xml or globally in a jetty.xml formatted file.

cheers,
jesse 

--
jesse mcconnell
jesse.mcconnell@xxxxxxxxx


On Mon, Jul 29, 2013 at 3:06 PM, Ranjith Koduri <nanikpranjith9@xxxxxxxxx> wrote:
Do I need to add a <resource-ref> to web.xml to get JNDI working or Is it fine to configure jetty-env.xml as I did?

    

Thanks & Regards,
Ranjith
MS-MIS, Univ Of Illinois at Chicago.





On Mon, Jul 29, 2013 at 2:27 PM, Ranjith Koduri <nanikpranjith9@xxxxxxxxx> wrote:
I moved webServer.start() before InitialContext but I'm getting the same error.






On Mon, Jul 29, 2013 at 2:16 PM, Joakim Erdfelt <joakim@xxxxxxxxxxx> wrote:
Your webServer.start() occurred after you attempted to lookup the JNDI reference.
That's not going to work, as the deployment of the WebAppContext is the one that sets up the JNDI reference.

You essentially asked for the information before the information even existed.

Move the webServer.start() to before the InitialContext reference.

--
Joakim Erdfelt <joakim@xxxxxxxxxxx>
Developer advice, services and support
from the Jetty & CometD experts


On Mon, Jul 29, 2013 at 12:07 PM, Ranjith Koduri <nanikpranjith9@xxxxxxxxx> wrote:
Hi,

I need to implement JNDI for Jetty 9.0.3 web server for H2 database using C3p0 connection pooling, I've placed both H2 and C3p0 jars in lib/ext of JETTY-HOME directory and I've created a jetty-env.xml file in my WEB-INF.

WEB-INF/jetty-env.xml


 <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
    <Configure class="org.eclipse.jetty.webapp.WebAppContext">
        <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
            <Arg>jdbc/testDS</Arg>
            <Arg>
           <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
           <Set name="driverClass">org.h2.Driver</Set>
           <Set name="jdbcUrl">jdbc:h2:/C:/data/test</Set>
           <Set name="user">sa</Set>
           <Set name="password"></Set>
                </New>
            </Arg>
        </New>
    </Configure>

I'm implementing embedded jetty with plus configuration enabled, by creating an instance of Jetty server from the main method of below class : WebServer.java


import java.io.File;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.ResourceCollection;
import org.eclipse.jetty.webapp.WebAppContext;

public class WebServer
{

    public static void main(String[] args)
    {
        // Creating Jetty Server on port 8080
        Server webServer = new Server(8080);
        org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(webServer);
        classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration",
                "org.eclipse.jetty.plus.webapp.PlusConfiguration");
        WebAppContext wac = new WebAppContext();
        // Set WAR Path to WebAppcontext from disk
        File warPath = new File("C:/Users/XXXX/src/com/UI");
        wac.setWar(warPath.getAbsolutePath());
        wac.setContextPath("/");
        wac.setBaseResource(new ResourceCollection(new String[] { "./WebContent", "build/classes" }));
        webServer.setHandler(wac);
        try
        {
            InitialContext ic = new InitialContext();
                DataSource myDS = (DataSource)ic.lookup("java:comp/env/jdbc/testDS");     
            System.out.println("param ::: "+myDS);
            webServer.start();
            webServer.join();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }

}

I get following error, how can I resolve this?


javax.naming.NameNotFoundException; remaining name 'env/jdbc/testDS'
    at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:505)
    at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:536)
    at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:551)
    at org.eclipse.jetty.jndi.java.javaRootURLContext.lookup(javaRootURLContext.java:117)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.server.WebServer.main(WebServer.java:37)




_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users




_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



Back to the top