4

我在 Jetty 中配置 JNDI 资源时遇到了很多困难。我已经使用 context.xml 和 Resource 节点轻松地在 Tomcat 中工作。已尝试在 jetty-env.xml 及其 context.xml 文件的版本中指定 Jetty 中的资源,但我最终得到了相同的异常。这是资源定义的 context.xml 版本:

<?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 文档中看到 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

社区的任何见解将不胜感激!

4

2 回答 2

1

对于Jetty7 ,您必须遵循这些说明。对于较旧的码头

我看到您正在尝试使用 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 依赖项:

于 2013-04-10T20:32:06.973 回答
0

问题不在于serverName方法。方法不存在。都没有portNumber,等等。您不能直接使用驱动程序。

如果您查看 jetty doc,它建议了非池数据源的替代方案。但可能你想要一个游泳池。所以,这个配置

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

已编辑

关于你的新问题。不知道发生了什么。看起来码头在创建临时目录时遇到了问题。根据文档,对于 Maven 插件,临时目录是${basedir}/target. 检查您的 jetty maven 插件配置,检查临时主管是否正确以及 jetty 是否具有该目录的权限。

于 2013-02-04T10:22:10.560 回答