2017-07-06 84 views
0

我正在嘗試使用插件jaxb2-maven-plugin從wsdl創建Java類。如何在jaxb2-maven-plugin version 2中從WSDL創建類java?

我與1.5版得到它和下面的代碼(鏈接:Generate classes with jaxb2-maven-plugin from WSDL):

 <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>jaxb2-maven-plugin</artifactId> 
       <version>1.5</version> 
       <executions> 
        <execution> 
         <id>xjc</id> 
         <goals> 
          <goal>xjc</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <!-- Package to store the generated file --> 
        <packageName>com.example.demo.wsdl</packageName> 
        <!-- Treat the input as WSDL --> 
        <wsdl>true</wsdl> 
        <!-- Input is not XML schema --> 
        <xmlschema>false</xmlschema> 
        <!-- The WSDL file that you saved earlier --> 
        <schemaFiles>horarios.wsdl</schemaFiles> 
        <!-- The location of the WSDL file --> 
        <schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory> 
        <!-- The output directory to store the generated Java files --> 
        <outputDirectory>${project.basedir}/src/main/java</outputDirectory> 
        <!-- Don't clear output directory on each run --> 
        <clearOutputDir>false</clearOutputDir> 
       </configuration> 
      </plugin> 

但是,當我更改爲2.3.1,我得到以下錯誤:

Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:xjc (xjc) on project demo: MojoExecutionException: NoSchemasException -> [Help 1] 

有人知道如何使用WSDL文件與這個新的插件版本?

回答

0

我已經找到解決方案。

當JAXB2 Maven的插件版本爲> = 2.0,你必須使用如下配置:

   <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>jaxb2-maven-plugin</artifactId> 
       <version>2.3.1</version> 
       <executions> 
        <execution> 
         <id>xjc</id> 
         <goals> 
          <goal>xjc</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <packageName>com.example.demo.wsdl</packageName> 
        <sourceType>wsdl</sourceType> 
        <sources> 
         <source>src/main/resources/horarios.wsdl</source> 
        </sources> 
        <outputDirectory>target/generated-sources/</outputDirectory> 
        <clearOutputDir>false</clearOutputDir> 
       </configuration> 
      </plugin> 

的區別不僅是sintaxis。該版本不會在項目內創建類(src/main/java),它會在您編寫的目錄outputDirectory和包packageName中創建。當你使用生成的類時,它是透明的,就好像它在同一個項目中一樣。

+0

相關的更多信息: https://stackoverflow.com/questions/35242941/jaxb-maven-plugin-not-generating-classes –

0

如果你想開始一個XSD:

   <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>jaxb2-maven-plugin</artifactId> 
       <version>2.3.1</version> 
       <executions> 
        <execution> 
         <id>xjc</id> 
         <goals> 
          <goal>xjc</goal> 
         </goals> 
        </execution> 
       </executions> 

       <configuration> 
        <xjbSources> 
         <xjbSource>src/main/resources/global.xjb</xjbSource> 
        </xjbSources> 
        <sources> 
         <source>src/main/resources/Ventas.xsd</source> 
        </sources> 
        <outputDirectory>${basedir}/src/main/java</outputDirectory> 
        <clearOutputDir>false</clearOutputDir> 
       </configuration> 
      </plugin>