gwt jetty jndi lookup fails

坚强是说给别人听的谎言 提交于 2019-12-05 13:49:14

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.


  • 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



Save the settings and launch the webapp in development mode.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!