Jdbc 在Jetty中配置JNDI资源SQL

Jdbc 在Jetty中配置JNDI资源SQL,jdbc,jetty,jndi,Jdbc,Jetty,Jndi,在Jetty中配置JNDI资源有很多困难。我已经使用context.xml和资源节点在Tomcat中轻松实现了这一点。已经尝试在Jetty-env.xml及其context.xml文件的版本中指定Jetty中的资源,但我最终得到了相同的异常。以下是资源定义的context.xml版本: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"

在Jetty中配置JNDI资源有很多困难。我已经使用context.xml和资源节点在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>
此异常似乎与直觉相反,因为我可以在中看到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

如果社区有任何见解,我们将不胜感激

问题不在于
serverName
方法。方法不存在。上的
端口号
等。您不能直接使用驱动程序

如果您看看jetty,它会为非池数据源提供一种替代方案。但很可能你想要一个游泳池。所以这个


com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc:jtds:sqlserver://:/
jdbc.user
jdbc.pass
已编辑


关于你的新问题。不知道发生了什么。看起来jetty在创建新的应用程序时遇到了问题。根据,对于Maven插件,临时目录是
${basedir}/target
。查看jetty maven插件配置,检查temporal director是否正确,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>


或者使用Maven::

按照这些说明,我现在在尝试启动服务器时遇到空指针异常。这是在下载commons dbcp和commons pool的jar之后。堆栈跟踪如下:
INFO:oejd.DeploymentManager:deployableadded:C:\jetty-hightide-8.1.7.v20120910\contents\verivo-env.xml 2013-02-04 10:09:26.186:警告:oejw.WebInfConfiguration:无法作为webapp tmp dir name java.lang.NullPointerException的一部分生成resourceBase。。。警告:oejw.WebAppContext:context o.e.j.w.WebAppContext{/,null}java.lang.NullPointerException启动失败
我已编辑了我的答案,但不清楚问题出在哪里。让我看看你的配置。
<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>
<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>