Setting up a JNDI SQL resource in Jetty

I am having difficulty setting up a JNDI resource in Jetty. I got this to work in Tomcat easily using context.xml and node resource. There have been attempts to point the resource to Jetty in both the jetty-env.xml file and their version of the context.xml file, but I am getting the same exception. Here is the contextual version of the resource definition:

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

      

The exception when trying to start JNDI is:

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)

      

This exception seems counter intuitive because I see in the Microsoft JDBC Driver 4.0 for SQL Server documentation that servername is listed as a valid property.

Also, I ran the command below to make sure all the expected jar files seem to be included. Specifically for jndi and sqljdbc.

java -jar start.jar --list-options

      

Below are links to tutorials and documentation that I used to get where I am.

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

      

Any insight the community has gained would be greatly appreciated!

+3


source to share


2 answers


You must follow these instructions for Jetty7 . For older Jetty .

I see that you are trying to use Sql Server, so you need to use net.sourceforge.jtds.jdbcx.JtdsDataSource as shown in the example:



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

      

Also add to [jetty_home] / lib / ext the desired jTDS library or using Maven: Maven dependency :

+1


source


The problem isn't the method serverName

. The method doesn't exist. Neither portNumber

, etc. On. You cannot use the driver directly.

If you look at doc jetty it offers an alternative for Non-pooling DataSources. But you probably want a pool. So this is 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>

      



Edited

About your new problem. Not sure if this is happening. It looks like jetty is having problems creating a temporary directory . According to the doc , for the Maven plugin, the temporary directory ${basedir}/target

. Review your jetty plugin configuration for maven if the temp director is correct and if jetty has permissions for that directory.

0


source







All Articles