2015-05-12 202 views
10

我已經添加了以下插件安裝到Maven構建中的pom.xmlMaven的JAXB2:XJC未能生成代碼

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>jaxb2-maven-plugin</artifactId> 
    <executions> 
     <execution> 
      <phase>generate-sources</phase> 
      <goals> 
       <goal>xjc</goal> 
      </goals> 
      <configuration> 
       <extension>true</extension>        
       <clearOutputDir>false</clearOutputDir> 
       <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory> 
       <schemaFiles>myapp.xsd</schemaFiles>               
       <outputDirectory>${basedir}/src/main/java</outputDirectory>   
       <bindingDirectory>src/main/resources/xsd</bindingDirectory>  
       <bindingFiles>myapp-bindings.xjb</bindingFiles> 
      </configuration> 
     </execution> 
    </executions>      

</plugin> 

以下是編譯錯誤。

[INFO] Ignored given or default xjbSources [C:\WorkSpace\MyApp\src\main\xjb], since it is not an existent file or directory. 
[INFO] Ignored given or default sources [C:\WorkSpace\MyApp\src\main\xsd], since it is not an existent file or directory. 
[WARNING] No XSD files found. Please check your plugin configuration. 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.273s 
[INFO] Finished at: Tue May 12 16:24:26 EDT 2015 
[INFO] Final Memory: 9M/124M 
[INFO] ------------------------------------------------------------------------ 
[WARNING] The requested profile "dev-artifactory" could not be activated because it does not exist. 
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.1:xjc (default) on project pml-jasypt-authentication-service: MojoExecutionException: NoSchemasException -> [Help 1] 

我很困惑,爲什麼插件沒有引用配置中指定的路徑和文件。

回答

4

今天我有同樣的問題,並解決它通過把:

<version>1.6</version> 

的插件定義(這是一般的好做法做)

13

2.1版本已經改變如何指定源

http://mojo.codehaus.org/jaxb2-maven-plugin/xjc-mojo.html#sources

<configuration> 
... 
    <sources> 
    <source>some/explicit/relative/file.xsd</source> 
    <source>/another/absolute/path/to/a/specification.xsd</source> 
    <source>a/directory/holding/xsds</source> 
</sources> 
</configuration> 

我遇到的其他問題,整個世界爲1.6建議jshark堅持這樣是一個很好的計劃

5

2.1版有一個bug。

您可以使用<version>2.2</version>新語法:

<configuration> 
... 
    <sources> 
    <source>some/explicit/relative/file.xsd</source> 
    <source>/another/absolute/path/to/a/specification.xsd</source> 
    <source>a/directory/holding/xsds</source> 
</sources> 
</configuration> 

您可以使用<version>1.6</version>與舊的語法:

<configuration> 
    ... 
    <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory> 
    <schemaFiles>myapp.xsd</schemaFiles> 
</configuration> 
0

我們還可以使用如下:

  <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>jaxb2-maven-plugin</artifactId> 
      <version>1.5</version> 
      <executions> 
       <execution> 
        <id>id1</id> 
        <goals> 
         <goal>xjc</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>src/main/java</outputDirectory> 
         <clearOutputDir>false</clearOutputDir> 
         <packageName>com.subu.xsd.model</packageName> 
         <schemaDirectory>src/main/java/schemadir</schemaDirectory> 
         <schemaFiles>XYZ.xsd</schemaFiles> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
0

我通過將編譯器版本設置爲JDK 1.8jaxb2-maven-plugin版本1.5 根據documention,它將使用最低JDK 1.6 [如果鏈接在站點中更改,鏈接可能會死掉]。例如:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.mntq.jaxb.xsd.to.pojo</groupId> 
    <artifactId>XsdToPojo</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 


    <build> 
     <finalName>PersistencePoJO</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
      <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> 
       <!-- The package of your generated sources --> 
       <packageName>com.mntq.jaxb.pojo</packageName> 
      </configuration> 
     </plugin> 
     </plugins> 
    </build> 
</project> 
相關問題