gwt jetty jndi查找失败

gwt jetty jndi查找失败,gwt,jetty,jndi,Gwt,Jetty,Jndi,我将gwt与jetty一起使用,但希望将jndi用于数据源,因此遵循了EclipseGWT jetty jndi的文档,并在下面运行了我的gwt应用程序 在eclipse中使用以下选项运行我的gwt应用程序 -noserver -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -startupUrl myapp.html -logLevel INFO -codeServerPort 9997 -war war\location -

我将gwt与jetty一起使用,但希望将jndi用于数据源,因此遵循了EclipseGWT jetty jndi的文档,并在下面运行了我的gwt应用程序

在eclipse中使用以下选项运行我的gwt应用程序

 -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配置下的My jetty-env.xml

<?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>  
剩余名称“java:comp”


看起来Eclipse/jetty无法找到jndi数据源。有什么建议吗???

以上配置中有两个问题

  • -noserver in run选项用于禁止jetty运行。它用于在tomcat等外部服务器上运行Web应用程序。要在GWT开发模式下的嵌入式jetty服务器上运行webapp,不需要此选项
  • 在jetty-web.xml中,jdbc/MSSQLDS应更改为java:/comp/env/jdbc/MSSQLDS
在GWT开发模式下,设置要在嵌入式Jetty服务器上运行的JNDI数据源的步骤如下。(我以mysql数据源为例,但步骤与其他数据源相同)

  • 将jetty命名-*.jar、jetty plus-*.jar添加到项目构建路径中,如下面的屏幕截图所示。可使用位于/usr/share/Jetty/lib的Jetty lib。您可以在生产中使用其他web服务器,如tomcat,但这些服务器没有添加到web-INF/lib-dir中。如果jetty也用于生产环境,则可将其添加到WEB-INF/lib dir中


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

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

    java:/comp/env/jdbc/dev
    jdbc:mysql://localhost:3306/dev?autoReconnect=true
    发展
    发展
    

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

  • 要更正此问题,请转到运行配置并打开应用程序的运行配置。选择Arguments选项卡并向VM Arguments添加以下行

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

运行配置的屏幕截图




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

看看另一个设置JNDI的线程,在嵌入式Jetty中使用数据源并不容易,但对我来说很有效。我贴了一个关于我是如何做这件事的小提纲。也许会有帮助。谢谢你的评论,事实上,我是在跟踪你提到的链接,如果你看到我有mycustomjetty luancher,就会发现上面的错误..jyo:1。)你有jndi.properties吗?(或者,您可以添加命令行arg
-Djava.naming.factory.initial=org.mortbay.naming.InitialContextFactory
)2。)您是否也在web.xml中定义了一个
?我应该将jndi.properties放在什么/哪里。.是的,-D虚拟机选项没有改进。。我在想我可能错过了一些类路径的东西。。任何想法..我的类路径中有jettyplus jars jettynaming jar我还需要更多吗??
    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)
<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>