本文介绍了Jersey maven-wadl-plugin无法解析HttpServletRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

I am generating an extended WADL witht the maven-wadl-plugin at buildtime following the excellent examples here and particluarly here.

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

I have verified that it works as expected unless my resource class includes a reference to the HttpServletRequest class and then it fails with a missing required class:

[错误]无法执行目标com.sun.jersey.contribs:maven-wadl-plugin :1.17:生成(生成)项目wadl:执行生成目标com.sun.jersey.contribs:maven-wadl-plugin:1.17:生成失败:执行com.sun.jersey.contribs时所需的类丢失:maven -wadl-plugin:1.17:generate:Ljavax / servlet / http / HttpServletRequest;

我没有看到任何类似的问题,我可以找不到任何关系d bug报告。我该怎么做才能解决这个问题?

I don't see any similar questions and I can't find any related bug reports. What can I do to fix this?

支持信息:

以下是运行时的完整信息 - X:

Here is the full message from running with -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

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

I am testing this out in a project that has just one example resource class:

@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。

I am using Jersey 1.7 and Jetty 8.0.4.v20111024. Here is the full 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. 添加servlet-api作为直接依赖

  2. 不要使用m2e嵌入式安装maven来生成wadl,使用外部
    安装。 (在本例中为Maven 3.0.4)

这篇关于Jersey maven-wadl-plugin无法解析HttpServletRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 23:31