2013-02-01 113 views
3

我在配置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 

任何洞察社區將不勝感激!

回答

0

問題不在於serverName方法。方法不在那裏。 portNumber等都沒有。您不能直接使用該驅動程序。

如果你看看碼頭doc,它建議非池化數據源的替代方案。但很可能你想要一個游泳池。所以,這個config

<New class="org.apache.commons.dbcp.BasicDataSource"> 
    <Set name="driverClassName">com.microsoft.sqlserver.jdbc.SQLServerDriver</Set> 
    <Set name="url">jdbc:jtds:sqlserver://<host>:<port>/<database_name></Set> 
    <Set name="username">jdbc.user</Set> 
    <Set name="password">jdbc.pass</Set> 
</New> 

編輯

關於你的新的問題。不知道它發生了什麼。看起來碼頭在創建temporary directory時遇到問題。根據doc,對於Maven插件,臨時目錄是${basedir}/target。檢查您的jetty maven插件配置檢查是否臨時主管是否正確,以及碼頭是否擁有該目錄的權限。

+0

感謝您的迴應! – Dubius

+1

按照這些說明,我正在嘗試啓動服務器時收到空指針異常。這是在下載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

+0

我編輯了我的答案,但不清楚問題出在哪裏。以我看你的配置。 – jddsantaella

1

您必須遵循Jetty7的這些說明。 舊版Jetty

我看到你試圖使用SQL Server,所以,你需要使用net.sourceforge.jtds.jdbcx.JtdsDataSource如圖所示樣品中:

<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource"> 
    <Arg></Arg> 
    <Arg>jdbc/DSTest</Arg> 
    <Arg> 
     <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource"> 
      <Set name="User">user</Set> 
      <Set name="Password">pass</Set> 
      <Set name="DatabaseName">dbname</Set> 
      <Set name="ServerName">localhost</Set> 
      <Set name="PortNumber">1433</Set> 
     </New> 
    </Arg> 
    </New> 

此外,添加到[jetty_home]/lib/ext所需的庫jTDS或使用Maven:Maven dependency