Content jetty-web.xml in / WEB-INF:
<Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Array id="plusConfig" type="java.lang.String"> <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item> <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item> <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item> <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item> <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item> <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item> <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item> </Array> <Call class="java.lang.System" name="setProperty"> <Arg>java.naming.factory.initial</Arg> <Arg><Property name="java.naming.factory.initial" default="org.eclipse.jetty.jndi.InitialContextFactory"/></Arg> </Call> <Call class="java.lang.System" name="setProperty"> <Arg>java.naming.factory.url.pkgs</Arg> <Arg><Property name="java.naming.factory.url.pkgs" default="org.eclipse.jetty.jndi"/></Arg> </Call> </Configure>
Content jetty-plus.xml in / WEB-INF:
<Configure id="Server" class="org.eclipse.jetty.server.Server"> <Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="setServerDefault"> <Arg><Ref refid="Server" /></Arg> <Call name="addAfter"> <Arg name="afterClass">org.eclipse.jetty.webapp.FragmentConfiguration</Arg> <Arg> <Array type="String"> <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item> <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item> </Array> </Arg> </Call> </Call> </Configure>
This is my calling code in the Servlet init () method:
Context _initCtx = new InitialContext(); Context _envCtx = (Context) _initCtx.lookup("java:comp/env");
Error:
javax.naming.NameNotFoundException; remaining name 'env' at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:449) 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(Unknown Source)
I am running vanilla GWT 2.7 and I am trying to use JNDI search in my server code. I also attached the project jetty-all-8.1.9.v20130131.jar and jetty-plus-8.1.9.v20130131.jar to the project, since some of the Context and JNDI classes are not in the GWT banks. I tried to check the version of the pier in GWT, and I got the following:
Server server = new Server(7070); System.out.println(server.getVersion()); 8.yz-SNAPSHOT
I saw a solution in which you can configure other JNDI methods, however, since I work in GWT, I can only work with the jetty-web.xml and jetty-plus.xml files.
When debugging a servlet, I get context for:
Context _envCtx = (Context) _initCtx.lookup("java:comp");
But not for:
Context _envCtx = (Context) _initCtx.lookup("java:comp/env");
Stacktrace above.
I am really stuck here. Are there any berth gurus there?
Change 1:
Jetty-env.xml added:
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure id='portal' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="DStest" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg></Arg> <Arg>jdbc/DSTest</Arg> <Arg> <New class="org.hsqldb.jdbcDriver"> <Set name="Url">jdbc:hsqldb:hsql://localhost</Set> <Set name="User">sa</Set> <Set name="Password"></Set> </New> </Arg> </New> </Configure>
And this is to my web.xml:
<resource-ref> <description>Primary database</description> <res-ref-name>jdbc/DSTest</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
However, _envCtx is null with the exception below. _initCtx.lookup ("java: comp") returns an instance of org.eclipse.jetty.jndi.NamingContext.
Context _initCtx = new InitialContext(); Context _envCtx = (Context) _initCtx.lookup("java:comp/env");
leads to
javax.naming.NameNotFoundException; remaining name 'env'
Edit 2:
I need to miss something else (main) .... ??!? I changed this 1 line in jetty-env.xml to:
<Arg><Ref refid="portal"/>jdbc/DSTest</Arg>
And doctype:
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
I did not find a more suitable .dtd for v8.X Another problem.