[英]Generate Serializable classes from a rest WADL with maven
I need to generate classes that implement Serializable
from a rest WADL using a maven plugin. 我需要使用maven插件从其余的WADL生成实现
Serializable
类。 I am able to do this with WSDL projects by adding a jaxb-bindings.xml
but this is not working for WADL project. 我可以通过添加
jaxb-bindings.xml
来处理WSDL项目,但这不适用于WADL项目。
Edit: Now I am getting this error when generating the files 编辑:现在生成文件时出现此错误
Failed to execute goal org.apache.cxf:cxf-wadl2java-plugin:3.2.0:wadl2java (generate-sources) on project my_project: java.lang.RuntimeException: Error compiling schema from WADL : " http://localhost:8080/rest_web/rest/application.wadl " is not a part of this compilation.
无法在项目my_project上执行目标org.apache.cxf:cxf-wadl2java-plugin:3.2.0:wadl2java(generate-sources):java.lang.RuntimeException:从WADL编译架构时出错:“ http:// localhost:8080 /rest_web/rest/application.wadl “不是此编译的一部分。 Is this a mistake for " http://localhost:8080/rest_web/rest/application.wadl/xsd2.xsd "?
这是“ http:// localhost:8080 / rest_web / rest / application.wadl / xsd2.xsd ”的错误吗? -> [Help 1]
-> [帮助1]
web app pom.xml that generates the WADL: 生成WADL的Web应用程序pom.xml:
<plugin>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>maven-wadl-plugin</artifactId>
<version>1.19.4</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
<configuration>
<wadlFile>${project.build.outputDirectory}/application.wadl</wadlFile>
<formatWadlFile>true</formatWadlFile>
<baseUri>http://${server}:8080/${project.name}/rest</baseUri>
<packagesResourceConfig>
<param>webservice.rest</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>
Client pom.xml file: 客户端pom.xml文件:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-wadl2java-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/target/generated-sources</sourceRoot>
<wadlOptions>
<wadlOption>
<wadl>http://localhost:8080/rest_web/rest/application.wadl</wadl>
<extraargs>
<extraarg>-verbose</extraarg>
<extraarg>-xjc-extension</extraarg>
</extraargs>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/META-INF/jaxb/jaxb-bindings.xml</bindingFile>
</bindingFiles>
<packagename>org.apache.cxf.systest.jaxrs.codegen.service</packagename>
<schemaPackagenames>
<schemaPackagename>http://superbooks=org.apache.cxf.systest.jaxrs.codegen.schema</schemaPackagename>
</schemaPackagenames>
</wadlOption>
</wadlOptions>
</configuration>
<goals>
<goal>wadl2java</goal>
</goals>
</execution>
</executions>
</plugin>
jaxb-bindings.xml jaxb-bindings.xml
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<globalBindings>
<serializable uid="1" />
</globalBindings>
</bindings>
The reason is that you have multiple XSD schemas (imported xsd files or explicitly defined <xs:schema>
tags) in <grammars>
block. 原因是在
<grammars>
块中有多个XSD模式(导入的xsd文件或明确定义的<xs:schema>
标记)。 You need one root <xs:schema>
tag inside <grammars>
block in your wadl to get XJB bindings to work with wadl2java
. 在wadl的
<grammars>
块中需要一个根<xs:schema>
根标签,以获取XJB绑定以与wadl2java
一起wadl2java
。 I'm looking for workaround without wadl editing now but still not succeeded, and I would be really grateful if somebody share the solution. 我现在正在寻找无需进行wadl编辑的解决方法,但仍然没有成功,如果有人分享解决方案,我将非常感谢。
Best regards, Aliaksei 此致Aliaksei
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.