gwt码头jndi查找失败 [英] gwt jetty jndi lookup fails

查看:124
本文介绍了gwt码头jndi查找失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jetty上使用gwt,但想使用jndi作为数据源,所以遵循eclipse gwt jetty jndi的文档,并在下面执行我的gwt应用程序。

运行我的gwt在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

在WEB-INF配置下的我的jetty-env.xml

 <?xml version =1.0encoding =ISO-8859-1?> 
<!DOCTYPE配置PUBLIC - // Mort Bay Consulting // DTD配置// EN
http://jetty.mortbay.org/configure.dtd\">
< Configure class =org.mortbay.jetty.webapp.WebAppContext>
< New id =MSSQLDSclass =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>

< /新建>
< / Arg>
< / New>
< / Configure>

当我运行我的应用程序时,出现错误消息

 在端口8888 
起码头[WARN]上下文com.healthfortis.MyCustomJettyLauncher$WebAppContextWithReload@2ed7c530 {/失败启动时,C:\workspace\hf-SRC \src\main\webapp}
javax.naming.NameNotFoundException;




剩余名称'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)
在javax。 naming.InitialContext.lookup(InitialContext.java:392)
在org.mortbay.jetty.plus.webapp.EnvConfiguration.createEnvContext(EnvConfiguration.java:51)
在org.mortbay.jetty.plus。在org.mortbay.jetty.webapp.WebAppContext.startContext webapp.EnvConfiguration.configureWebApp(EnvConfiguration.java:103)
(WebAppContext.java:1217)
。在org.mortbay.jetty.handler.ContextHandler。 DOSTART(ContextHandler.java:513)
在org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
在com.healthfortis.MyCustomJettyLauncher $ WebAppContextWithReload.doStart( MyCustomJettyLauncher.java:459)在org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
在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)
在com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:494)
在com.google.gwt.dev.DevModeBase.startUp (DevModeBase.java:1058)
位于com.google.gwt.dev.DevModeBase.run(DevModeBase.java:800)
位于com.google.gwt.dev.DevMode.main(DevMode.java :304)

看起来像eclipsse / jetty无法找到jndi datasource ..任何建议?

解决方案

以上配置有两个问题:


  • -noserver in run选项是禁用的码头从跑步。它用于在外部服务器(如tomcat等)上运行Web应用程序。要在GWT开发模式下在嵌入式jetty服务器上运行webapp,不需要此选项。 精氨酸> JDBC / MSSQLDS< /精氨酸>应该更改为< Arg> java:/ comp / env / jdbc / MSSQLDS< / Arg>



设置在GWT开发模式下在嵌入式Jetty服务器上运行的JNDI数据源如下。 (我已经使用mysql数据源作为示例,但其他数据源的步骤相同)




  • 添加码头命名 - *。jar,jetty-plus - *。jar来项目构建路径,如下面的屏幕截图所示。可以使用/ usr / share / jetty / lib中的Jetty lib。可以使用其他Web服务器,如生产中的tomcat,它们不会添加到WEB-INF / lib目录中。如果jetty用于生产env,那么它们可以被添加到WEB-INF / lib目录中。











  • 将以下内容的jetty-web.xml添加到WEB-INF目录中



     < Arg> java:/ comp / env / jdbc的/ dev< /精氨酸> 
    < 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>







  • 运行GWT项目作为Web应用程序。您将得到 javax.naming.NoInitialContextException


  • 要解决此问题,请转至运行配置并打开应用程序的运行配置。选择Arguments选项卡并将以下行添加到VM参数中



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




  • 运行配置的屏幕截图




    < img src =https://i.stack.imgur.com/Au6Rl.pngalt =在这里输入图片描述>






    保存设置并以开发模式启动webapp。


    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??

    解决方案

    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.

    这篇关于gwt码头jndi查找失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆