4

I am using gwt with jetty but want use jndi for datasource so followed the documentation for eclipse gwt jetty jndi and did below to run my gwt app

Run my gwt app with following options in eclipse

 -noserver 
-remoteUI "${gwt_remote_ui_server_port}:${unique_id}"
-startupUrl myapp.html
-logLevel INFO 
-codeServerPort 9997
-war war\location 
-server com.myproject.MyCustomJettyLauncher 
com.my.apps.app

My jetty-env.xml under WEB-INF configuration

<?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="MSSQLDS" class="org.mortbay.jetty.plus.jndi.Resource">
    <Arg></Arg>
    <Arg>jdbc/MSSQLDS</Arg>
    <Arg>
     <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
                 <Set name="User">dbuser</Set>
                 <Set name="Password">pwd</Set>
                 <Set name="DatabaseName">mydatabase</Set>
                 <Set name="ServerName">localhost</Set>
                 <Set name="PortNumber">1433</Set>

     </New>
    </Arg>
   </New>
</Configure>  

When I run my app i get below error

Starting Jetty on port 8888
   [WARN] Failed startup of context com.healthfortis.MyCustomJettyLauncher$WebAppContextWithReload@2ed7c530{/,C:\workspace\hf-src\src\main\webapp}
javax.naming.NameNotFoundException; 

remaining name 'java:comp'

    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:578)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:680)
    at org.mortbay.naming.local.localContextRoot.lookup(localContextRoot.java:164)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at org.mortbay.jetty.plus.webapp.EnvConfiguration.createEnvContext(EnvConfiguration.java:51)
    at org.mortbay.jetty.plus.webapp.EnvConfiguration.configureWebApp(EnvConfiguration.java:103)
    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 com.healthfortis.MyCustomJettyLauncher$WebAppContextWithReload.doStart(MyCustomJettyLauncher.java:459)
    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 com.healthfortis.MyCustomJettyLauncher.start(MyCustomJettyLauncher.java:660)
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:494)
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1058)
    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:800)
    at com.google.gwt.dev.DevMode.main(DevMode.java:304)

looks like eclipsse/jetty is not able to find jndi datasource..any suggestions??

su jyo
  • 41
  • 1
  • 2
  • Setting up JNDI, and using DataSources with the embedded Jetty was not easy, but it worked for me. I posted a little outline of how I did it in [this answer](http://stackoverflow.com/questions/5078273/running-gwt-speedtracer-without-jetty/5079773#5079773). Maybe it helps. – Chris Lercher Mar 28 '11 at 07:31
  • Thanks for your comments Infact I was following the link you mentioned if you see I have mycustomjetty luancher get the above error.. – su jyo Mar 28 '11 at 13:50
  • jyo: 1.) Do you have a jndi.properties? (Alternatively, you can add the command line arg `-Djava.naming.factory.initial=org.mortbay.naming.InitialContextFactory`) 2.) Did you also define a `` in your web.xml? – Chris Lercher Mar 28 '11 at 14:31
  • What/where should I put the jndi.properties..Yes did -D vm options no improvement .. I was thinking may be I missing some classpath stuff.. any thoughts..I have jetty*plus jars jetty*naming jar in my classpath do I need more?? – su jyo Mar 28 '11 at 18:18
  • Take a look at another thread [here](http://stackoverflow.com/questions/2131798/jetty-mysql-connection-pool-configuration-error-javax-naming-namenotfoundexcepti) – Piyush Mattoo Mar 28 '11 at 06:34

1 Answers1

4

There are two issues in the above configuration

  • -noserver in run option is to disable jetty from running. It is used to run Web Application on external server like tomcat etc. To run webapp on embedded jetty server in GWT development mode this option is not required.
  • In jetty-web.xml <Arg>jdbc/MSSQLDS</Arg> should be changed as <Arg>java:/comp/env/jdbc/MSSQLDS</Arg>

Steps to set up a JNDI datasource to run on embedded Jetty server in GWT Development mode is as follows. (I have used mysql datasource as example but steps are same for other datasources)

  • Add jetty-naming-*.jar, jetty-plus-*.jar to project build path as shown in following screen shot. Jetty lib available at /usr/share/jetty/lib may be used. One may use other web servers like tomcat in production they are not added to WEB-INF/lib dir. In case jetty is used for production env also then they may be added to WEB-INF/lib dir.

Build Path


  • Add jetty-web.xml with following content to WEB-INF directory

    <Arg>java:/comp/env/jdbc/dev</Arg>
    <Arg>
        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
            <Set name="Url">jdbc:mysql://localhost:3306/dev?autoReconnect=true
            </Set>
            <Set name="User">dev</Set>
            <Set name="Password">dev</Set>
        </New>
    </Arg>
    

  • Run the GWT project as Web Application. You will get javax.naming.NoInitialContextException

  • To rectify this go to Run Configurations and open the application's run configuration. Select Arguments tab and add following line to VM Arguments

    -Djava.naming.factory.initial=org.mortbay.naming.InitialContextFactory

Screen shot of Run Configuration


enter image description here


Save the settings and launch the webapp in development mode.

Maithilish
  • 965
  • 12
  • 21