我有以下问题。我有项目A,其中有common.xsd文件,项目B依赖于 项目A并具有main.xsd文件。我使用的片段文件,我的B中POM看起来像这样jaxb,wsdl文件,重复类
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-Xannotate</arg>
<arg>-Xnamespace-prefix</arg>
<arg>-nv</arg>
</args>
<extension>true</extension>
<forceRegenerate>true</forceRegenerate>
<bindingDirectory>${basedir}/src/main/resources/xjb</bindingDirectory>
<bindingIncludes>
<include>*.xjb</include>
</bindingIncludes>
<schemas>
<schema>
<fileset>
<directory>${basedir}/src/main/resources/xsd/</directory>
<includes>
<include>B.xsd</include>
</includes>
</fileset>
</schema>
<schema>
<dependencyResource>
<groupId>AgroupID</groupId>
<artifactId>AartifactID</artifactId>
<resource>xsd/A.xsd</resource>
</dependencyResource>
</schema>
</schemas>
<episodes>
<episode>
<groupId>AgroupID</groupId>
<artifactId>AartifactID</artifactId>
</episode>
</episodes>
<debug>true</debug>
<verbose>true</verbose>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-namespace-prefix</artifactId>
<version>1.1</version>
</plugin>
</plugins>
</configuration>
</plugin>
,但我也有WSDL文件,在那里我有这个进口
<xsd:import namespace="SOME_NAMASPACE" schemaLocation="main.xsd" />
,当我改变
<include>B.xsd</include>
到
<include>main.wsdl</include>
and turn wsdl by
<wsdl>true</wsdl>
类正确生成,但是从项目一 这些常见的类被复制。当我XSD的WSDL,而不是它的工作好
- 更新 -
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<excludes>
<exclude>classpath:xsd/common.xsd</exclude>
</excludes>
<sourceRoot>${generated_src}</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.basedir}PATH_TO_WSDL/main.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
- 更新 -
WSDL文件的片段
<wsdl:types>
<xsd:schema
xmlns=...
targetNamespace=...
xmlns:carlic="NAMESPACE_OF_MAIN_XSD">
<xsd:import namespace="NAMESPACE_OF_MAIN_XSD" schemaLocation="main.xsd" />
<xsd:element name="carData" type="carlic:CarData" />
</xsd:schema>
</wsdl:types>
我使用的这个插件](http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html),以从WSDL产生的类。我认为这是一个很好的替代“maven-jaxb2-plugin”关于 wsdl世代。 – Xstian 2014-09-24 15:27:22
也axis2(另一个Apache项目)是伟大的。包含一个wsdl2java程序,该程序将生成所有存根类,以便将程序挂接到该程序中。 (虽然我认为cxf现在是一个更加维持一天) – SnakeDoc 2014-09-24 16:36:49
@ Xstian,但是有可能使用这个插件实现相同的结果。因为当我使用它。它似乎忽略了我以前的选择。我得到的错误,因为插件找不到来自common.xsd – Unyx 2014-09-25 07:25:59