Jetty and Wildfly JNDI compatibility

Viewed 198

Im a little rusty on configurations as I have not written anything from scratch for years.. I am writing a webservice which I want to use locally with jetty in eclipse and then on the server with Wildfly. I have figured out both separately, but not for both to work at the same time.. What I have is: In java Im looking for dbsource with

final DataSource ds = (DataSource) ctx.lookup("java:/comp/env/jdbc/smartieDB"); 

For jetty this works in jetty-env.xml:

<Configure class="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
    <New id="smartieDB" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg>jdbc/smartieDB</Arg> ..... etc

web.xml:

<resource-ref>
        <description>DB Connection</description>
        <res-ref-name>/comp/env/jdbc/smartieDB</res-ref-name> <!--<-this was for wildfly, for jetty this only works:  jdbc/smartieDB -->
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

In wildfly the datasource is configured with jndi-name:

<datasource jndi-name="java:/comp/env/jdbc/smartieDB" pool-name="PostgrePool">

Any ideas how can I optimize this so that I dont have to do the checks where it is jetty locally and when it is run on the server? Grateful for all tips!!!

Cheers, Nikki

0 Answers
Related