我对maven-jaxb2-plugin
有疑问。
我想要实现的是从x个不同的wsdl生成源到不同的包。
我想避免多个<execution>
的方法,所以当我添加另一个wsdl时,我可以保持pom.xml不变。
我配置了这样的maven插件:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<schemaDirectory>src/main/resources/webservice/wsdl</schemaDirectory>
<schemaIncludes>
<include>orig/*.wsdl</include>
</schemaIncludes>
<bindingDirectory>src/main/resources/webservice/xjb</bindingDirectory>
<bindingIncludes>
<include>orig/*.xjb</include>
</bindingIncludes>
</configuration>
</execution>
</executions>
</plugin>
根据我的理解,这种方式我指定了.wsdl位置以及绑定文件位置。
现在在一个示例绑定文件中(所有这些都以相同的方式构造)我得到了以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:version="2.1">
<jaxb:bindings schemaLocation="../../wsdl/orig/soap1.wsdl"
node="*/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="my.package.com.soap1" />
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
另一项服务是soap2,soap3等,它们都有类似的绑定文件。如果我理解这是正确的,多亏了这个connfig我应该能够为我的肥皂生成域对象,每个都在单独的包中。
但是当我运行maven clean compile
时,我得到了以下输出:
[ERROR] Error while parsing schema(s).Location [ file:/C:/Users/me/workspace/orig-project/src/main/resources/webservice/wsdl/orig/soap1.wsdl{202,39}].
org.xml.sax.SAXParseException; systemId: file:/C:/Users/me/workspace/orig-project/src/main/resources/webservice/wsdl/orig/soap1.wsdl; lineNumber: 202; columnNumber: 39; 'Line' **is already defined**
更重要的是,出于测试目的,我尝试配置插件来处理单独的<execution>
中的每个wsdl(我想在最终代码中避免这种情况),我观察到的是在第一个ex之后。处理了soap1.wsdl,正确创建了包,但根本没有创建其他soap.wsdl的包。 (只是第一次处理)。
这有什么问题,是否有可能实现我的目标?
更新 为了澄清我想要实现的目标,我将在那里发布适用于我的解决方案,但每次添加新的webservice时它都会强制我编辑POM:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.1</version>
<executions>
<execution>
<id>soap1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/webservice/wsdl</schemaDirectory>
<schemaIncludes>
<include>Soap1.wsdl</include>
</schemaIncludes>
<generatePackage>my.package.com.soap1</generatePackage>
</configuration>
</execution>
<execution>
<id>soap2</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/webservice/wsdl</schemaDirectory>
<schemaIncludes>
<include>Soap2.wsdl</include>
</schemaIncludes>
<generatePackage>my.package.com.soap2</generatePackage>
</configuration>
</execution>
<execution>
<id>soap3</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/webservice/wsdl</schemaDirectory>
<schemaIncludes>
<include>Soap3.wsdl</include>
</schemaIncludes>
<bindingDirectory>src/main/resources/webservice/xjb</bindingDirectory>
<bindingIncludes>
<include>soap3.xjb</include>
</bindingIncludes>
<generatePackage>my.package.com.soap3</generatePackage>
</configuration>
</execution>
</executions>
</plugin>
看起来(也许?)有一些问题:
<jaxb:schemaBindings>
<jaxb:package name="my.package.com.soap1" />
</jaxb:schemaBindings>
在我的第一个(也是想要的)解决方案中。有什么想法吗?