Jetty 9 Maven插件和没有合适构造函数的JNDI

时间:2013-02-20 18:26:37

标签: jetty maven-jetty-plugin

我正在尝试使用Jetty 9 Maven插件来创建JNDI资源。相同的配置与Jetty 8一起正常工作但与Jetty 9产生java.lang.IllegalStateException: No suitable constructor。以下是相关文件:

的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 /测试/资源/码头-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>

和实际错误:

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>

将注释更改为两行(以恢复Jetty 8)并正确启动应用程序。

1 个答案:

答案 0 :(得分:7)

您需要将jetty-ds-dev.xml文件中的以下行作为第二行:

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

不确定为什么它在没有指定configure.dtd的情况下使用8,但绝对应该存在,并且版本为9_0。

问候 扬