Question

I'm trying to get JNDI resource creation to work with the Jetty 9 Maven plugin. The same configuration works correctly with Jetty 8 but yields an java.lang.IllegalStateException: No suitable constructor with Jetty 9. Here are the relevant files:

pom.xml:

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>jetty-jndi</artifactId>
  <version>1.0</version>
  <build>
    <plugins>
      <plugin>
        <!-- <groupId>org.mortbay.jetty</groupId>
        <version>8.1.9.v20130131</version> -->
        <groupId>org.eclipse.jetty</groupId>
        <version>9.0.0.RC0</version>
        <artifactId>jetty-maven-plugin</artifactId>
        <configuration>
          <webAppConfig>
            <jettyEnvXml>src/test/resources/jetty-ds-dev.xml</jettyEnvXml>
          </webAppConfig>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.hsqldb</groupId>
      <artifactId>hsqldb</artifactId>
      <version>2.2.9</version>
    </dependency>
  </dependencies>
</project>

src/test/resources/jetty-ds-dev.xml:

<?xml version="1.0"?>
<Configure id="Server" class="org.eclipse.jetty.webapp.WebAppContext">
  <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg>jdbc/test</Arg>
    <Arg>
      <New class="org.hsqldb.jdbc.JDBCDataSource">
        <Set name="DatabaseName">mem:foo</Set>
        <Set name="User">SA</Set>
      </New>
    </Arg>
  </New>
</Configure>

and the actual error:

2013-02-20 10:22:23.464:WARN:oejx.XmlConfiguration:main: Config error at <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">|??<Arg>jdbc/test</Arg>|??<Arg>|???<New class="org.hsqldb.jdbc.JD
BCDataSource">|????<Set name="DatabaseName">mem:foo</Set>|????<Set name="User">SA</Set>|???</New>|??</Arg>|?</New> java.lang.IllegalStateException: No suitable constructor: <New id="DSTest" class="org
.eclipse.jetty.plus.jndi.Resource">
                <Arg>jdbc/test</Arg>
                <Arg>
                        <New class="org.hsqldb.jdbc.JDBCDataSource">
                                <Set name="DatabaseName">mem:foo</Set>
                                <Set name="User">SA</Set>
                        </New>
                </Arg>

Change the comment two lines down (to restore Jetty 8) and the application launches correctly.

Était-ce utile?

La solution

You need the following line in your jetty-ds-dev.xml file as the 2nd line:

<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

Not sure why it worked with 8 without having the configure.dtd specified, but definitely should be there, and at version 9_0.

regards Jan

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top