2014-09-24 100 views
2

我有以下问题。我有项目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> 
+1

我使用的这个插件](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

+1

也axis2(另一个Apache项目)是伟大的。包含一个wsdl2java程序,该程序将生成所有存根类,以便将程序挂接到该程序中。 (虽然我认为cxf现在是一个更加维持一天) – SnakeDoc 2014-09-24 16:36:49

+0

@ Xstian,但是有可能使用这个插件实现相同的结果。因为当我使用它。它似乎忽略了我以前的选择。我得到的错误,因为插件找不到来自common.xsd – Unyx 2014-09-25 07:25:59

回答

3

插件生成来自WSDL的接口。

<plugin> 
     <groupId>org.apache.cxf</groupId> 
     <artifactId>cxf-codegen-plugin</artifactId> 
     <version>2.7.3</version> 
     <executions> 
      <execution> 
       <id>generate-sources</id> 
       <phase>generate-sources</phase> 
       <configuration> 
        <wsdlOptions> 
         <wsdlOption> 
          <wsdl>${basedir}/src/main/resources/your.wsdl</wsdl> 
          <extraargs> 
           <extraarg>-nexclude</extraarg> 
           <extraarg>NameSpaceOfxsd</extraarg> 
          </extraargs> 
         </wsdlOption> 
        </wsdlOptions> 
       </configuration> 
       <goals> 
        <goal>wsdl2java</goal> 
       </goals> 
      </execution> 
     </executions> 
    </plugin> 

<extraarg>-nexclude</extraarg><extraarg>NameSpaceOfxsd</extraarg>能避免这些类的产生。

插件从XSD生成类。

 <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/</directory> 
          <includes> 
           <include>*.xsd</include> 
          </includes> 
         </fileset> 
        </schema> 
       </schemas> 
       <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> 

插件于每一类和接口添加到源代码。

  <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>build-helper-maven-plugin</artifactId> 
      <version>1.1</version> 
      <executions> 
       <execution> 
        <id>add-source</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>add-source</goal> 
        </goals> 
        <configuration> 
         <sources> 
          <source>target/generated-sources/xjc</source> 
          <source>target/generated-sources/cxf</source> 
         </sources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
+0

它应该是common.xsd或main.xsd的命名空间。 Wsdl文件导入main.xsd?我试图包含命名空间,但是我仍然有同样的错误,找不到来自common.xsd的类型 – Unyx 2014-09-25 10:36:27

+0

在我的wsdl文件中,我使用main.xsd中的类型difinition。设为typeA。在复杂类型typeA的main.xsd定义中,我使用common.xsd(cmns:car)中的类型,并且出现错误,因为cmns:car无法解析 – Unyx 2014-09-25 10:41:11

+0

您可以添加wsdl的示例吗?为了帮助你更好:) – Xstian 2014-09-25 10:55:35