1
我正在尝试更改从wsdl生成的类的名称(我不想直接修改任何wsdl或xsd文件)。问题是它的定义是在一个单独的xsd文件中。JAXWS:如何更改在外部XSD中定义的CXF生成的类名称?
WSDL的结构基金看起来是这样的:
main.wsdl:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://foo.bar/zee">
<wsdl:import location="typedef.wsdl" namespace="http://foo.bar/wee">
</wsdl:import>
...
</wsdl:definitions>
typedef.wsdl:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Foo" targetNamespace="http://foo.bar/wee">
<wsdl:types>
<xsd:schema>
<xsd:import namespace="http://foo.bar/wee/schema" schemaLocation="FooBar.xsd"/>
</xsd:schema>
</wsdl:types>
...
<wsdl:definitions>
FooBar.xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://foo.bar/wee/schema">
...
<xsd:complexType name="FooType">
<xsd:sequence>
...
</xsd:complexType>
</xsd:schema>
现在假设我想重命名F oooType类到Foo。阅读后:JAXB: How to change XJC-generated classes names when attr type is specified in XSD?我已经创建了以下绑定文件。
jaxws_bindings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1"
wsdlLocation="http://127.0.0.1:8431/Foo/types.wsdl">
<jxb:bindings schemaLocation="http://127.0.0.1:8431/Foo/FooBar.xsd">
<jxb:bindings node="//xs:complexType[@name='FooType']">
<jxb:class name="Foo"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
但我得到的是一个错误:
[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.7.0:wsdl2java (generate-sources) on
project foo: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:2.7.0:wsdl2java failed:
file:/E:/sources/.../jaxws_bindings.xml [8,95]: "http://127.0.0.1:8431/Foo/FooBar.xsd" is not a part of
this compilation. Is this a mistake for "http://127.0.0.1:8431/Foo/FooBar.xsd"? -> [Help 1]
我已经尝试了一切,来到我的脑海里,但仍然没有什么接近成功。 任何人都碰巧知道如何做到这一点?
PS:为了生成我用maven CXF代码生成插件与pom.xml的一个下面的配置的类:
<build>
<finalName>${project.groupId}.${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>http://127.0.0.1:8431/Foo/main.wsdl</wsdl>
<extraargs>
<extraarg>-client</extraarg>
</extraargs>
<bindingFiles>
<bindingFile>jaxws_bindings.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>