我在配置Jetty中的JNDI資源時遇到了很多困難。我已經使用context.xml和Resource節點輕鬆地在Tomcat中工作。已嘗試在Jetty中指定jetty中的資源,並在jetty-env.xml和它們的context.xml文件的版本中指定資源,但最終得到相同的異常。以下是資源定義的context.xml的版本:在Jetty中配置JNDI資源SQL
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/SQLDB</Arg>
<Arg>
<New class="com.microsoft.sqlserver.jdbc.SQLServerDriver">
<Set name="serverName">SQLDB.domain.com</Set>
<Set name="portNumber">1433</Set>
<Set name="databaseName">DBName</Set>
<Set name="userName">UName</Set>
<Set name="password">PWord</Set>
</New>
</Arg>
</New>
</Configure>
報錯例外,當我嘗試啓動JNDI是:
java.lang.NoSuchMethodException: class com.microsoft.sqlserver.jdbc.SQLServerDriver.setServerName(class java.lang.String)
2013-02-01 16:57:39.061:WARN:oejd.DeploymentManager:Unable to reach node goal: started
java.lang.NoSuchMethodException: class com.microsoft.sqlserver.jdbc.SQLServerDriver.setServerName(class java.lang.String)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.set(XmlConfiguration.java:585)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:390)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:819)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1132)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1035)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:783)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:398)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:349)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:302)
at org.eclipse.jetty.deploy.providers.ContextProvider.createContextHandler(ContextProvider.java:86)
at org.eclipse.jetty.deploy.App.getContextHandler(App.java:100)
at org.eclipse.jetty.deploy.bindings.StandardDeployer.processBinding(StandardDeployer.java:36)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:494)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:141)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:145)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:56)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:540)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:403)
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:337)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:121)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:555)
at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:230)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:81)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:96)
at org.eclipse.jetty.server.Server.doStart(Server.java:277)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1265)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:468)
at org.eclipse.jetty.start.Main.start(Main.java:616)
at org.eclipse.jetty.start.Main.main(Main.java:92)
此異常似乎與直覺相反,因爲我可以在Microsoft JDBC Driver 4.0 for SQL Server documentation見該serverName被列爲有效的屬性。
此外,我運行了下面的命令來驗證所有預期的jar文件似乎都包含在內。特別是對於jndi和sqljdbc。
java -jar start.jar --list-options
以下是我用來獲取自己所在位置的教程和文檔的鏈接。
http://wiki.eclipse.org/Jetty/Feature/JNDI
http://www.eclipse.org/jetty/documentation/current/jndi-datasource-examples.html
http://www.eclipse.org/jetty/documentation/current/jndi.html#configuring-env-entries
任何洞察社區將不勝感激!
感謝您的迴應! – Dubius
按照這些說明,我正在嘗試啓動服務器時收到空指針異常。這是在下載js commons-dbcp和commons-pool之後。堆棧跟蹤如下: 'INFO:oejd.DeploymentManager:Deployable added:C:\ jetty-hightide-8.1.7.v20120910 \ contexts \ verivo-env.xml 2013-02-04 10:09:26.186:警告:oejw。WebInfConfiguration:無法生成resourceBase爲web應用TMP目錄名稱的一部分 顯示java.lang.NullPointerException ... 警告:oejw.WebAppContext:背景oejwWebAppContext的啓動失敗{/,空} java.lang.NullPointerException' – Dubius
我編輯了我的答案,但不清楚問題出在哪裏。以我看你的配置。 – jddsantaella