How to setup connection pool with GWT / Jetty in eclipse?

Sorry if this question seems repetitive, but I was unable to clarify a workable solution from the search results for existing posts.

I have a web application that uses a JDBC connection pool. The connection pool resource is defined in the war file of the meta-inf / context.xml file. When I deploy the war file to tomcat, this file is copied (and renamed to match the name of my war file) to the tomcat conf / catalina / localhost folder. My code gets the connection datasource object like this:

Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
datasource = (DataSource) envCtx.lookup("jdbc/MYDB");


and my context.xml has the following resource:

<Resource name="jdbc/MYDB" 


This all works well when the war file is deployed to tomcat.

However, during development in eclipse and due to GWT dependencies, I often have to debug using the GWT embedded in the jetty container.

When I do this, the InitialContext () call ends with the message:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial


I tried using jetty-env.xml in war web-inf but that didn't work either (same error), maybe syntax error in jetty-env.xml file or something.

Here is my pier:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="OTMFTDB" class="">
        <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
            <Set name="User">username</Set>
            <Set name="Password">password</Set>
            <Set name="DatabaseName">testdb</Set>
            <Set name="ServerName">myremote.database.server</Set>
            <Set name="PortNumber">1433</Set>


Lastly, if I change the name of jetty-env.xml to jetty-web.xml, then I get a 503 HTML error when I try to connect the browser. (eclipse shows the following error: [WARN] Failed to start context com.g $ WebAppContextWithReload @ 111a20c {/, E: \ dev \ src \ servers \ webservice \ war} java.lang .ClassNotFoundException: org.eclipse.jetty.server.Server)

So, I believe jetty-env was not loaded but jetty-net, but my jetty is clearly interfering with the jetty-env settings for jetty.


source to share

2 answers

You are missing org.eclipse.jetty.server.Server, but I think it is not the correct class. GWT 2.5.1 uses jetty 6.1.11 and according to that is the org.eclipse.jetty package from Jetty 7, not 6!

I had a similar problem and solved it by adding the jetty-naming and jetty-plus libraries project to the project. This is a maven project, so I added it to the pom.xml:



Without maven, you can download jetty-naming and jetty-plus banks from the internet.

My resource is PostgreSQL JDBC driver. Everything now works - in host mode - the resource config loaded from jetty-web.xml. And when I create a war and deploy to Tomcat, the resource is obtained from context.xml.


<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/web">
    <Resource auth="Container" driverClassName="org.postgresql.Driver"
        maxActive="100" maxIdle="30" maxWait="200" name="jdbc/postgres"
        username="testuser" password="testpass" type="javax.sql.DataSource"
        url="jdbc:postgresql://localhost:5433/resolver" />



<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
    <New id="GWT_HOSTED_MODE_DB" class="">
            <New class="org.apache.commons.dbcp.BasicDataSource">
                <Set name="driverClassName">org.postgresql.Driver</Set>
                <Set name="url">jdbc:postgresql://localhost:5433/resolver</Set>
                <Set name="username">testuser</Set>
                <Set name="password">testpass</Set>


Also my web.xml contains this link:

    <description>Postgres Connection pool datasource</description>


The data source is loaded like this (simplified):

DataSource dataSource = (DataSource) new InitialContext().lookup("java:/comp/env/jdbc/postgres");




While I'm not familiar with your pier problem, I know that you can use your own servlet container instead of the GWT servlet container using the -noserver flag. It works great and allows me to use any other server in hosted mode.



All Articles