Jetty-maven-plugin does not add JNDI data source resource from Jetty.xml

I can't seem to add my data source using the jetty-maven plugin. No errors occur, but when I look in context, the data source was not added. I checked that the path to the file is correct and that it parses it (entering the wrong class names leads to errors). I tried to use the tag and configure it as a WebAppContext configuration, but this file is completely ignored.

pom.xml

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>8.1.3.v20120416</version>
  <configuration>
    <jettyXml>somePath/jetty.xml</jettyXml>
  </configuration>
  <dependencies>        
    <dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.0-801.jdbc4</version>
  </dependency>
 </dependencies>
</plugin>

jetty.xml

<Configure class="org.eclipse.jetty.server.Server">

<New id="jdbc/postgres" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg>jdbc/postgres</Arg>
    <Arg>
        <New class="org.postgresql.ds.PGSimpleDataSource">
            <Set name="User">postgres</Set>
            <Set name="Password">postgres</Set>
            <Set name="DatabaseName">myDB</Set>
            <Set name="ServerName">localhost</Set>
            <Set name="PortNumber">5432</Set>
        </New>
    </Arg>
</New>

Java code

Context ctx = new InitialContext();
Context context = (Context) ctx.lookup("java:comp/env");
ds = (DataSource) context.lookup("jdbc/postgres");

Any help would be appreciated.

+3
source share
2 answers

For people who are still looking for a solution, see the accepted answer in this question .

The key here is to use jetty-env.xml, not jetty.xml.

References

+1

web.xml:

<resource-ref>
    <res-ref-name>jdbc/postgres</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
0

All Articles