Jetty data source, Hibernate, data source not found

I am trying to configure a data source in Jetty 7.4. I was able to do this successfully with my webapp in Tomcat context.xml.

Here is what I have in the jetty.xml file (this will be the only application in this instance of the pier, so I do not mind having a database connection on the server - I would prefer not to configure it inside the war). It is at the very bottom just above the last </Configure>:

<New class="org.eclipse.jetty.plus.jndi.Resource" id="myDB">
    <Arg>
      <Ref id="Server"/>
    </Arg>
    <Arg>jdbc/myDB</Arg>
    <Arg>
        <New class="com.microsoft.sqlserver.jdbc.SQLServerDataSource">
            <Set name="URL">jdbc:sqlserver://SERVERNAME;databaseName=DATABASENAME;sendStringParametersAsUnicode=false</Set>
            <Set name="user">USERNAME</Set>
            <Set name="password">PASSWORD</Set>
        </New>
    </Arg>
</New>

In my webapp WEB-INF / web.xml:

<resource-ref>
  <description>Database Connection</description>
  <res-ref-name>jdbc/myDB</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

Finally, in my hibernate.cfg.xml:

<property name="connection.datasource">java:comp/env/jdbc/myDB</property>

However, I get a datasource not found error, and I also see the following NameNotFoundException:

javax.naming.NameNotFoundException; remaining name 'env/jdbc/myDB'

When I run Jetty with debugging turned on, it looks like it is logging the name and that's it, although I'm far from being a Jetty expert. Did I miss a step here? What is left?

+1
1

, bizzarerry . "java: comp/env", JNDI, . , Spring / JNDI bean (, ).

Try:

<property name="connection.datasource">jdbc/myDB</property>

Hibernate.

+4

All Articles