[英]WADL Generation Tool
是否有一個工具可以將Java文件描述為REST服務作為參數,並生成一個wadl文件。
我遇到了同樣的問題:使用RESTeasy並希望找到一種自動生成WADL的方法。
做了一些研究並得出了以下解決方案。
pom.xml
: <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)。
創建src/main/doc/
文件夾並在下面創建兩個文件。
文件: 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" />
轉到項目文件夾並運行以下命令:
$ mvn compile com.sun.jersey.contribs:maven-wadl-plugin:generate
應該生成files \\target\\classes\\application.wadl
(WADL本身)和\\target\\classes\\xsd0.xsd
(資源的模式 - 它由application.wadl使用)。
根據需要編輯和使用它們。
PS。:請記住,這是maven-wadl-plugin的一個非常簡單的用法。 它可以做更多。 要更好地了解它,請參閱其他答案中提到的zip文件(由Pavel Bucek提供)。
是的,請參閱Jersey樣本的gerenate-wadl [1]樣本(查找maven-wadl-plugin)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.