【发布时间】:2012-03-14 17:06:42
【问题描述】:
对不起,如果这个问题似乎重复,但我无法从现有帖子的搜索结果中找到可行的解决方案。
我有一个使用 JDBC 连接池的 Web 应用程序。连接池资源在war 文件的meta-inf/context.xml 中定义。当我将战争文件部署到 tomcat 时,该文件被复制(并重命名以匹配我的战争文件的名称)到 tomcat 的 conf/catalina/localhost 文件夹。我的代码像这样获取连接的数据源对象:
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
datasource = (DataSource) envCtx.lookup("jdbc/MYDB");
我的 context.xml 定义了以下资源:
<Resource name="jdbc/MYDB"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
username="username"
password="password"
url="jdbc:sqlserver://myremote.database.server:1433;databaseName=testdb"
/>
war 文件部署到 tomcat 后,所有这些都可以正常工作。
但是,在eclipse中开发过程中,由于GWT的依赖,我经常需要使用GWT内置的jetty容器进行调试。
当我这样做时,InitialContext() 调用失败并显示以下消息:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
我尝试在战争的 web-inf 中使用 jetty-env.xml,但这也不起作用(同样的错误),可能是 jetty-env.xml 中的语法错误或其他原因。
这是我的码头环境:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="OTMFTDB" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/MYDB</Arg>
<Arg>
<New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
<Set name="User">username</Set>
<Set name="Password">password</Set>
<Set name="DatabaseName">testdb</Set>
<Set name="ServerName">myremote.database.server</Set>
<Set name="PortNumber">1433</Set>
</New>
</Arg>
</New>
</Configure>
最后一件事,如果我将 jetty-env.xml 的名称更改为 jetty-web.xml,那么当我尝试连接浏览器时会收到 503 HTML 错误。 (eclipse显示以下错误: [WARN] com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload@111a20c{/,E:\dev\src\servers\webservice\war} 上下文启动失败 java.lang.ClassNotFoundException: org.eclipse.jetty.server.Server)
所以我相信 jetty-env 没有加载而 jetty-web 加载了,但是我的 jetty-web 显然会干扰 GWT 的 jetty 设置。
【问题讨论】:
标签: eclipse gwt jdbc jetty jndi