I need to implement JNDI for the Jetty 9.0.3 web server for the H2 database using the C3p0 connection pool, I placed both the H2 and C3p0 boxes in the lib / ext directory from the JETTY-HOME directory, and I created jetty-env.xml in my WEB-INF.
WEB-INF / berth-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 implement a built-in jetty with plus support enabled by creating an instance of the Jetty server from the main method below the 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) {
I get the following error, how can I solve it?
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)
source share