我正在使用GWT和Jetty,但想要使用JNDI来获取数据源,因此按照Eclipse GWT 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
我的jetty-env.xml文件在WEB-INF下的配置
<?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>
当我运行我的应用程序时,我会收到以下错误信息。
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;
剩余名称为'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)
看起来eclipse/jetty无法找到JNDI数据源..有任何建议吗?
-Djava.naming.factory.initial=org.mortbay.naming.InitialContextFactory
) 2.) 你也在 web.xml 中定义了<resource-ref>
吗? - Chris Lercher