java - Jersey maven-wadl-plugin no puede resolver HttpServletRequest
(1)
Estoy generando una WADL ampliada con el plugin maven-wadl en el momento de la construcción, siguiendo los excelentes ejemplos aquí y, en particular, aquí .
He verificado que funciona como se espera a menos que mi clase de recursos incluya una referencia a la clase HttpServletRequest y luego falla con una clase requerida faltante:
[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;
No veo ninguna pregunta similar y no puedo encontrar ningún informe de errores relacionado. ¿Qué puedo hacer para arreglar esto?
Información de soporte:
Aquí está el mensaje completo de ejecución con -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
Estoy probando esto en un proyecto que tiene solo una clase de recurso de ejemplo:
@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();
}
}
Estoy usando Jersey 1.7 y Jetty 8.0.4.v20111024. Aquí está el POM completo.
<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>
Ver comentarios.
- Agregue el servlet-api como una dependencia directa
- No utilice la instalación incrustada m2e de maven para generar el wadl, use una instalación externa. (Maven 3.0.4 en este caso)