WADL生成工具 [英] WADL Generation Tool

查看:111
本文介绍了WADL生成工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个工具可以将Java文件描述为REST服务作为参数,并生成一个wadl文件。

Is there a tool which takes a Java File what describes a REST service as a parameter and generates a wadl file out of that.

推荐答案

我遇到了同样的问题:使用RESTeasy并希望找到一种自动生成WADL的方法。

I had the same problem: was using RESTeasy and wanted to find a way to generate the WADL automatically.

做了一些研究并找到了下面的解决方案。

Did some research and came to the solution below.

<build>
<plugins>
    <plugin>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>maven-wadl-plugin</artifactId>
        <version>1.17</version>
        <executions>
            <execution>
                <id>generate</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <phase>${javadoc-phase}</phase>
            </execution>
        </executions>
        <configuration>
            <wadlFile>${project.build.outputDirectory}/application.wadl
            </wadlFile>
            <formatWadlFile>true</formatWadlFile>
            <baseUri>http://example.com:8080/rest</baseUri>
            <packagesResourceConfig>
                <param>com.example.rs.resource</param>
            </packagesResourceConfig>
            <wadlGenerators>
                <wadlGeneratorDescription>
                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
                    </className>
                    <properties>
                        <property>
                            <name>applicationDocsFile</name>
                            <value>${basedir}/src/main/doc/application-doc.xml</value>
                        </property>
                    </properties>
                </wadlGeneratorDescription>
                <wadlGeneratorDescription>
                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport
                    </className>
                    <properties>
                        <property>
                            <name>grammarsFile</name>
                            <value>${basedir}/src/main/doc/application-grammars.xml</value>
                        </property>
                    </properties>
                </wadlGeneratorDescription>
            </wadlGenerators>
        </configuration>
    </plugin>
</plugins>
</build>

注意 buildUri packagesResourceConfig 元素。您必须更改它们以反映项目的配置。您可能还想更改插件的版本(我使用的是1.17)。

Pay attention to the buildUri and packagesResourceConfig elements. You have to change them to reflect your project's configuration. You may also want to change the plugin's version (I used 1.17).

创建 src / main / doc / 文件夹并创建下面有两个文件。

Create the src/main/doc/ folder and create the two files below.

文件: application-doc.xml

内容:

<?xml version="1.0" encoding="UTF-8"?>
<applicationDocs targetNamespace="http://wadl.dev.java.net/2009/02">
    <doc xml:lang="en" title="A message in the WADL">This is added to the start of the generated application.wadl</doc>
</applicationDocs>

文件: application-grammars.xml

内容:

<?xml version="1.0" encoding="UTF-8" ?>
<grammars xmlns="http://wadl.dev.java.net/2009/02" />



3。运行maven命令。



转到项目文件夹并运行以下命令:

3. Run the maven command.

Go to the project folder and run the following command:

$ mvn compile com.sun.jersey.contribs:maven-wadl-plugin:generate

文件 \\\getget \classes \application.wadl (WADL本身)和 \\\ target \classes \ xsd0。应该生成xsd (资源的模式 - 它由application.wadl使用)。

The files \target\classes\application.wadl (the WADL itself) and \target\classes\xsd0.xsd (the schema of the resources - it's used by the application.wadl) should be generated.

根据需要编辑和使用它们。

Edit and use them as you wish.

PS:请记住,这是对maven-wadl-plugin的一个非常简单的使用。它可以做更多。要更好地了解它,请参阅其他答案中提到的zip文件(由Pavel Bucek提供)。

PS.: Bear in mind that this is a very simple use of the maven-wadl-plugin. It can do a lot more. To know it better, please refer to the zip file mentioned in the other answer (by Pavel Bucek).

这篇关于WADL生成工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆