用于REST API的Maven WADL插件跨越多个项目

时间:2017-11-15 21:43:31

标签: java rest maven wadl

我正在尝试maven-wadl-plugin。 (除了the Javadoc之外,我没有找到任何文件。)

我的项目具有用于不同Maven模块中的REST端点的类。并且WADL插件似乎无法达到它们。因此,在单个模块上运行会失败:

[ERROR] Failed to execute goal 
   com.sun.jersey.contribs:maven-wadl-plugin:1.19.4:generate (generate) 
on project bpds-resources: Execution generate of goal com.sun.jersey.contribs:maven-wadl-plugin:1.19.4:generate 
failed: A required class was missing while executing 
  com.sun.jersey.contribs:maven-wadl-plugin:1.19.4:generate: com/.../common/dto/BoxRequestDto

该插件也不支持从根项目运行。

1)AFAIK,maven-wadl-plugin解析来源。我的项目产生一个大阴影.jar,因此插件可以使用它而不关心内部依赖项。我可以让插件扫描工件吗?

2)有没有办法让它适用于多个项目?

1 个答案:

答案 0 :(得分:0)

我发现将项目依赖项添加到扫描模块可以正常工作。所以我在DTO类中添加了属性,现在它可以工作:

<build>
    <plugins>
        <plugin>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>maven-wadl-plugin</artifactId>
            <version>1.19.4</version>
            <dependencies>
                <dependency>
                    <groupId>org.glassfish.jersey.core</groupId>
                    <artifactId>jersey-server</artifactId>
                    <version>2.25.1</version>
                </dependency>
                <dependency>
                    <groupId>com.fasterxml.jackson.jaxrs</groupId>
                    <artifactId>jackson-jaxrs-json-provider</artifactId>
                    <version>2.8.10</version>
                </dependency>
                <dependency>
                    <groupId>org.glassfish.jersey.media</groupId>
                    <artifactId>jersey-media-multipart</artifactId>
                    <version>2.25.1</version>
                </dependency>
                <dependency>
                    <groupId>com.mycompany.bpds</groupId>
                    <artifactId>bpds-common</artifactId>
                    <version>${project.version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <phase>package</phase>

                    <configuration>
                        <wadlFile>${project.build.directory}/endpoints.wadl</wadlFile>
                        <formatWadlFile>true</formatWadlFile>
                        <baseUri>http://localhost:9021/</baseUri>
                        <packagesResourceConfig>
                            <param>com.mycompany.rest</param>
                        </packagesResourceConfig>
                        <wadlGenerators>
                            <!-- Doesn't work wit current version of Xerces.
                            <wadlGeneratorDescription>
                                <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc</className>
                                <properties>
                                    <property>
                                        <name>applicationDocsFile</name>
                                        <value>${project.build.directory}/app-wadl-doc.xml</value>
                                    </property>
                                </properties>
                            </wadlGeneratorDescription>
                            <wadlGeneratorDescription>
                                <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport</className>
                                <properties>
                                    <property>
                                        <name>grammarsFile</name>
                                        <value>${project.build.directory}/app-wadl-grammar.xml</value>
                                    </property>
                                </properties>
                            </wadlGeneratorDescription>
                            -->
                        </wadlGenerators>
                    </configuration>
                </execution>
            </executions>
        </plugin>