2015-05-12 16 views
10

Tôi đã thêm các plugin sau vào Maven xây dựng trong pom.xmlMaven jaxb2: XJC thất bại trong việc tạo ra mã

<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> 

Sau đây là các lỗi xây dựng.

[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] 

Tôi nhầm lẫn, tại sao plugin không đề cập đến đường dẫn và tệp được chỉ định trong cấu hình.

Trả lời

4

tôi đã cùng một vấn đề ngày hôm nay, và giải quyết nó bằng cách đặt:

<version>1.6</version> 

vào định nghĩa plugin (đó là trong thực tế tốt nói chung để làm)

13

phiên bản 2.1 đã thay đổi như thế nào nguồn được quy định

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

ví dụ

<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> 

Tôi đang gặp một thế giới hoàn toàn các vấn đề khác để gắn bó với 1.6 như jshark đề xuất là một kế hoạch tốt

5

phiên bản 2.1 có một lỗi.

Bạn có thể sử dụng <version>2.2</version> với cú pháp mới:

<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> 

Bạn có thể sử dụng <version>1.6</version> với cú pháp cũ:

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

Chúng tôi cũng có thể sử dụng như sau:

  <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

Tôi đã làm việc này bằng cách đặt phiên bản trình biên dịch thành JDK 1.8jaxb2-maven-plugin phiên bản 1.5 Theo số documention, nó sẽ hoạt động với tối thiểu JDK 1.6 [Liên kết có thể thả chết nếu thay đổi trong trang web]. Ví dụ:

<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> 
Các vấn đề liên quan