Jersey maven-wadl-plugin无法解析HttpServletRequest

时间:2013-12-24 19:48:31

标签: java maven jersey wadl

我正在构建时使用maven-wadl-plugin生成扩展的WADL,遵循优秀示例here并特别here

我已经验证它按预期工作除非我的资源类包含对HttpServletRequest类的引用,然后失败并且缺少必需的类:

[ERROR] Failed to execute goal com.sun.jersey.contribs:maven-wadl-plugin:1.17:generate (generate) on project wadl: Execution generate of goal com.sun.jersey.contribs:maven-wadl-plugin:1.17:generate failed: A required class was missing while executing com.sun.jersey.contribs:maven-wadl-plugin:1.17:generate: Ljavax/servlet/http/HttpServletRequest;

我没有看到任何类似的问题,我找不到任何相关的错误报告。我该怎么做才能解决这个问题?

支持信息:

以下是使用-X:

运行的完整信息
[INFO] 
[INFO] --- maven-wadl-plugin:1.17:generate (generate) @ wadl ---
[INFO] Loading wadlGenerator com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
[INFO] Loading wadlGenerator com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport
[INFO] Loading wadlGenerator com.sun.jersey.server.wadl.generators.resourcedoc.WadlGeneratorResourceDocSupport
Dec 24, 2013 12:51:09 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  example.rest.resources
Dec 24, 2013 12:51:09 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class example.rest.resources.HelloResource
Dec 24, 2013 12:51:09 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.920s
[INFO] Finished at: Tue Dec 24 12:51:09 CST 2013
[INFO] Final Memory: 15M/159M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.sun.jersey.contribs:maven-wadl-plugin:1.17:generate (generate) on project wadl: Execution generate of goal com.sun.jersey.contribs:maven-wadl-plugin:1.17:generate failed: A required class was missing while executing com.sun.jersey.contribs:maven-wadl-plugin:1.17:generate: Ljavax/servlet/http/HttpServletRequest;
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>com.sun.jersey.contribs:maven-wadl-plugin:1.17
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/jethoma/.m2/repository/com/sun/jersey/contribs/maven-wadl-plugin/1.17/maven-wadl-plugin-1.17.jar
[ERROR] urls[1] = file:/C:/Users/jethoma/.m2/repository/org/apache/maven/apache-maven/2.0.9/apache-maven-2.0.9.jar
[ERROR] urls[2] = file:/C:/Users/jethoma/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
[ERROR] urls[3] = file:/C:/Users/jethoma/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-10/doxia-sink-api-1.0-alpha-10.jar
[ERROR] urls[4] = file:/C:/Users/jethoma/.m2/repository/junit/junit/4.8.2/junit-4.8.2.jar
[ERROR] urls[5] = file:/C:/Users/jethoma/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar
[ERROR] urls[6] = file:/C:/Users/jethoma/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
[ERROR] urls[7] = file:/C:/Users/jethoma/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar
[ERROR] urls[8] = file:/C:/Users/jethoma/.m2/repository/xerces/xercesImpl/2.6.1/xercesImpl-2.6.1.jar
[ERROR] urls[9] = file:/C:/Users/jethoma/.m2/repository/com/sun/jersey/jersey-servlet/1.17/jersey-servlet-1.17.jar
[ERROR] urls[10] = file:/C:/Users/jethoma/.m2/repository/com/sun/jersey/jersey-server/1.17/jersey-server-1.17.jar
[ERROR] urls[11] = file:/C:/Users/jethoma/.m2/repository/asm/asm/3.1/asm-3.1.jar
[ERROR] urls[12] = file:/C:/Users/jethoma/.m2/repository/com/sun/jersey/jersey-core/1.17/jersey-core-1.17.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------: javax.servlet.http.HttpServletRequest
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

我正在一个只有一个示例资源类的项目中对此进行测试:

@Path("/hello")
public class HelloResource {

    @Context
    private HttpServletRequest req; 

    @GET
    @Path("{param}")
    public Response getMsg(@PathParam("param") String msg) {
        String output = "Hello : " + msg;
        return Response.status(200).entity(output).build();
    }
}

我正在使用Jersey 1.7和Jetty 8.0.4.v20111024。这是完整的POM。

<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>jersey.example</groupId>
    <artifactId>wadl</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>generate-wadl</name>
    <properties>
        <jersey-release-version>1.17</jersey-release-version>
        <jetty-release-version>8.0.4.v20111024</jetty-release-version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>${jersey-release-version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-server</artifactId>
            <version>${jetty-release-version}</version>
        </dependency>
    </dependencies>

    <build>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>javadoc</goal>
                        </goals>
                        <phase>compile</phase>
                    </execution>
                </executions>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <verbose>false</verbose>
                    <show>public</show>
                    <useStandardDocletOptions>false</useStandardDocletOptions>
                    <subpackages>example.rest.resources</subpackages>
                    <doclet>com.sun.jersey.wadl.resourcedoc.ResourceDoclet</doclet>
                    <docletArtifacts>
                        <docletArtifact>
                            <groupId>com.sun.jersey.contribs</groupId>
                            <artifactId>wadl-resourcedoc-doclet</artifactId>
                            <version>${jersey-release-version}</version>
                        </docletArtifact>
                        <!-- Also specify jersey and xerces as doclet artifacts as the ResourceDoclet 
                            uses classes provided by them to generate the resourcedoc. -->
                        <docletArtifact>
                            <groupId>com.sun.jersey</groupId>
                            <artifactId>jersey-server</artifactId>
                            <version>${jersey-release-version}</version>
                        </docletArtifact>
                        <docletArtifact>
                            <groupId>xerces</groupId>
                            <artifactId>xercesImpl</artifactId>
                            <version>2.6.1</version>
                        </docletArtifact>
                    </docletArtifacts>
                    <additionalparam>-output
                        ${project.build.outputDirectory}/resourcedoc.xml</additionalparam>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.sun.jersey.contribs</groupId>
                <artifactId>maven-wadl-plugin</artifactId>
                <version>${jersey-release-version}</version>
                <executions>
                    <execution>
                        <id>generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>compile</phase>
                    </execution>
                </executions>
                <configuration>
                    <wadlFile>${project.build.outputDirectory}/application.wadl</wadlFile>
                    <formatWadlFile>true</formatWadlFile>
                    <baseUri>http://example</baseUri>
                    <packagesResourceConfig>
                        <param>example.rest.resources</param>
                    </packagesResourceConfig>
                    <wadlGenerators>
                        <wadlGeneratorDescription>
                            <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc</className>
                            <properties>
                                <property>
                                    <name>applicationDocsFile</name>
                                    <value>${project.build.outputDirectory}/application-doc.xml</value>
                                </property>
                            </properties>
                        </wadlGeneratorDescription>
                        <wadlGeneratorDescription>
                            <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport</className>
                            <properties>
                                <property>
                                    <name>grammarsFile</name>
                                    <value>${project.build.outputDirectory}/application-grammars.xml</value>
                                </property>
                            </properties>
                        </wadlGeneratorDescription>
                        <wadlGeneratorDescription>
                            <className>com.sun.jersey.server.wadl.generators.resourcedoc.WadlGeneratorResourceDocSupport</className>
                            <properties>
                                <property>
                                    <name>resourceDocFile</name>
                                    <value>${project.build.outputDirectory}/resourcedoc.xml</value>
                                </property>
                            </properties>
                        </wadlGeneratorDescription>
                    </wadlGenerators>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>xml-maven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>transform</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
                <configuration>
                    <transformationSets>
                        <transformationSet>
                            <dir>${project.build.outputDirectory}</dir>
                            <includes>
                                <include>application.wadl</include>
                            </includes>
                            <stylesheet>${basedir}/src/main/resources/wadl-1.2.xsl</stylesheet>
                            <fileMappers>
                                <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                                    <pattern>\.wadl$</pattern>
                                    <replacement>.html</replacement>
                                </fileMapper>
                            </fileMappers>
                        </transformationSet>
                    </transformationSets>
                </configuration>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings 
                    only. It has no influence on the Maven build itself. -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>com.sun.jersey.contribs</groupId>
                                        <artifactId>maven-wadl-plugin</artifactId>
                                        <versionRange>[${jersey.version},)</versionRange>
                                        <goals>
                                            <goal>generate</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-javadoc-plugin</artifactId>
                                        <versionRange>[2.4,)</versionRange>
                                        <goals>
                                            <goal>javadoc</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>xml-maven-plugin</artifactId>
                                        <versionRange>[1.0,)</versionRange>
                                        <goals>
                                            <goal>transform</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

1 个答案:

答案 0 :(得分:1)

见评论。

  1. 将servlet-api添加为直接依赖
  2. 不要使用m2e嵌入式安装maven来生成wadl,使用外部 安装。 (在本例中为Maven 3.0.4)