Setting DataSource (JNDI) in GWT 1.6 (hosted mode - Jetty)

1,868 views
Skip to first unread message

wiltonj

unread,
Mar 12, 2009, 12:16:36 AM3/12/09
to Google Web Toolkit
Hi,
How to setting DataSource in GWT 1.6 (Hosted mode - Jetty)?

Hoping for some guidance.

Thanks & Regards,
Wilton

Nicolas Wetzel

unread,
Mar 12, 2009, 3:56:49 AM3/12/09
to Google-We...@googlegroups.com
Hi
these are some things you have to do for setting a datasource:

1: put two additionnals jars in your classpath: jetty-naming-6.1.11.jar and jetty-plus-6.1.11.jar to add some J2EE features on Jetty

2: change the startup JettyLauncher to your own custom JettyLauncher (works with -server option ) : put this line in the tab Arguments eclipse setting run program option:
-server com.myproject.MyCustomJettyLauncher

3 create your own MyCustomJettyLauncher : copy and past the JettyLauncher  to add some "Configuration"

private static String[] __dftConfigurationClasses = 
    {
        "org.mortbay.jetty.webapp.WebInfConfiguration", //
        "org.mortbay.jetty.plus.webapp.EnvConfiguration",//jetty-env
        "org.mortbay.jetty.plus.webapp.Configuration", //web.xml
        "org.mortbay.jetty.webapp.JettyWebXmlConfiguration",//jettyWeb
    } ;

and at the end of the start() method  call wac.setConfigurationClasses(__dftConfigurationClasses);

 WebAppContext wac = new WebAppContextWithReload(
        appRootDir.getAbsolutePath(), "/");
    wac.setConfigurationClasses(__dftConfigurationClasses);
    server.setHandler(wac);
    server.start();
    server.setStopAtShutdown(true);
 
4) edit a jetty-env.xml on the web-inf to specify a dataSource

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
    <New id="DSTest" class="org.mortbay.jetty.plus.naming.Resource">
        <Arg>jdbc/projectDS</Arg>
        <Arg>
            <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
                <Set name="Url">jdbc:mysql://localhost:3306/database
                </Set>
                <Set name="User">myUserName</Set>
                <Set name="Password">myPassword</Set>
            </New>
        </Arg>
    </New>
</Configure>

5) make a reference on it in your web-inf/web.xml

<resource-ref>
        <description>DataSource's project</description>
        <res-ref-name>jdbc/projectDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

it works for me

regards,

Nicolas Wetzel

sjachym

unread,
Apr 23, 2009, 12:35:36 PM4/23/09
to Google Web Toolkit
I follow the 5 steps, but when i'm running my Module GWT under Google
Eclipse Plugin, i have this errors :

[WARN] Configuration problem at <resource-
ref><description>DataSource's test project</description><res-ref-
name>jdbc/projectDS</res-ref-name><res-type>javax.sql.DataSource</res-
type><res-auth>Container</res-auth></resource-ref>
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

[WARN] Failed startup of context com.myproject.MyCustomJettyLauncher
$WebAppContextWithReload@1a663bb{/,C:\workspaceEclipse
\GwtSmartGwtGoogleEclipse\war}
javax.servlet.UnavailableException: Configuration problem

Can you help me for working too ? Thanks.

Chad

unread,
May 7, 2009, 12:24:06 PM5/7/09
to Google Web Toolkit
You can do this by configuring a jetty-web.xml file. I blogged what
worked for us at:

http://humblecode.blogspot.com/2009/05/gwt-16-using-jndi-datasource.html

Mark

unread,
Jun 5, 2009, 12:59:20 PM6/5/09
to Google Web Toolkit
Hi Chad,

I followed your guide, but I get an error when starting up hosted
mode:

[WARN] Config error at
<New id="website" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>java:comp/env/jdbc/database</Arg>
<Arg>
<New
class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/mydbname</Set>
<Set name="User">myusername</Set><Set name="Password">mypassword</
Set></New>
</Arg>
</New>

I read around and it seems that jetty thinks that the jetty-plus and
jetty-naming jars are not in my classpath, but I did add them to my
project file - any idea what could be missing?

Shouldn't we have an official example from GWT as well for this now
that the switch has been made to Jetty? Seems like a common thing
people would want to do,

Thanks,
Mark



On May 7, 12:24 pm, Chad <cha...@sbcglobal.net> wrote:
> You can do this by configuring ajetty-web.xml file. I blogged what

Henning

unread,
Jul 19, 2009, 3:00:34 PM7/19/09
to Google Web Toolkit
You have to add the jetty-*.jar's in the launch configuration
properties' classpath. The project classpath is not used for the
internal jetty server.

I made a description in my blog (in german):

http://curtstech.blogspot.com/2009/07/gwt-16-hosted-mode-internen-jetty.html

-Henning

Christian

unread,
Sep 16, 2009, 3:51:57 AM9/16/09
to Google Web Toolkit
Hi,

I followed the instructions from Nicolas to add the DataSource in the
Jetty config and now I'm facing this error:

[WARN] Configuration problem at <resource-ref><description>MySQl
Connection</description><res-ref-name>jdbc/skyline</res-ref-name><res-
type>javax.sql.DataSource</res-type><res-auth>Container</res-auth></
resource-ref>
java.lang.ClassCastException: org.mortbay.jetty.plus.naming.Resource
cannot be cast to org.mortbay.jetty.plus.naming.NamingEntry
at org.mortbay.jetty.plus.naming.NamingEntry.lookupNamingEntry
(NamingEntry.java:211)
at org.mortbay.jetty.plus.naming.NamingEntry.bindToENC
(NamingEntry.java:104)
at org.mortbay.jetty.plus.webapp.Configuration.bindResourceRef
(Configuration.java:73)
at org.mortbay.jetty.plus.webapp.AbstractConfiguration.initResourceRef
(AbstractConfiguration.java:262)
at
org.mortbay.jetty.plus.webapp.AbstractConfiguration.initWebXmlElement
(AbstractConfiguration.java:161)
at org.mortbay.jetty.webapp.WebXmlConfiguration.initialize
(WebXmlConfiguration.java:289)
at org.mortbay.jetty.plus.webapp.AbstractConfiguration.initialize
(AbstractConfiguration.java:133)
at org.mortbay.jetty.webapp.WebXmlConfiguration.configure
(WebXmlConfiguration.java:222)
at org.mortbay.jetty.plus.webapp.AbstractConfiguration.configure
(AbstractConfiguration.java:113)
at org.mortbay.jetty.webapp.WebXmlConfiguration.configureWebApp
(WebXmlConfiguration.java:180)
at org.mortbay.jetty.plus.webapp.AbstractConfiguration.configureWebApp
(AbstractConfiguration.java:96)
at org.mortbay.jetty.plus.webapp.Configuration.configureWebApp
(Configuration.java:124)
at org.mortbay.jetty.webapp.WebAppContext.startContext
(WebAppContext.java:1217)
at org.mortbay.jetty.handler.ContextHandler.doStart
(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:
448)
at skyline.frontend.server.helper.CustomJettyLauncher
$WebAppContextWithReload.doStart(CustomJettyLauncher.java:412)
at org.mortbay.component.AbstractLifeCycle.start
(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart
(HandlerWrapper.java:130)
at org.mortbay.jetty.handler.RequestLogHandler.doStart
(RequestLogHandler.java:115)
at org.mortbay.component.AbstractLifeCycle.start
(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart
(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start
(AbstractLifeCycle.java:39)
at skyline.frontend.server.helper.CustomJettyLauncher.start
(CustomJettyLauncher.java:464)
at com.google.gwt.dev.HostedMode.doStartUpServer(HostedMode.java:365)
at com.google.gwt.dev.HostedModeBase.startUp(HostedModeBase.java:590)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:397)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)

I have both necessary libraries in my WEB-INF/lib directory, created
the CustomJettyLauncher as described and added the xml config:

entry in web.xml:
<resource-ref>
<description>MySQl Connection</description>
<res-ref-name>jdbc/skyline</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

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.mortbay.jetty.webapp.WebAppContext">

<New id="skyline" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/skyline</Arg>
<Arg>
<New
class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/skyline</
Set>
<Set name="User">root</Set>
<Set name="Password">admin</Set>
</New>
</Arg>
</New>

</Configure>

Can anyone of you tell me, what I did wrong?

Kind Regards,
Christian

On Jul 20, 5:00 am, Henning <henning.br...@googlemail.com> wrote:
> You have to add the jetty-*.jar's in the launch configuration
> properties' classpath. The project classpath is not used for the
> internal jetty server.
>
> I made a description in my blog (in german):
>
> http://curtstech.blogspot.com/2009/07/gwt-16-hosted-mode-internen-jet...
> > > > Wilton- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages