How can I tell jaxb / Maven to generate multiple schema packages?

前端 未结 9 1830
旧时难觅i
旧时难觅i 2020-11-28 03:16

Example:

       
       
           org.jvnet.jaxb2.maven2         


        
9条回答
  •  -上瘾入骨i
    2020-11-28 03:24

    I had to specify different generateDirectory (without this, the plugin was considering that files were up to date and wasn't generating anything during the second execution). And I recommend to follow the target/generated-sources/ convention for generated sources so that they will be imported in your favorite IDE automatically. I also recommend to declare several execution instead of declaring the plugin twice (and to move the configuration inside each execution element):

    
      org.jvnet.jaxb2.maven2
      maven-jaxb2-plugin
      0.7.1
      
        
          schema1-generate
          
            generate
          
          
            src/main/resources/dir1
            
              shiporder.xsd
            
            com.stackoverflow.package1
            ${project.build.directory}/generated-sources/xjc1
          
        
        
          schema2-generate
          
            generate
          
          
            src/main/resources/dir2
            
              books.xsd
            
            com.stackoverflow.package2
            ${project.build.directory}/generated-sources/xjc2
          
        
      
    
    

    With this setup, I get the following result after a mvn clean compile

    $ tree target/
    target/
    ├── classes
    │   ├── com
    │   │   └── stackoverflow
    │   │       ├── App.class
    │   │       ├── package1
    │   │       │   ├── ObjectFactory.class
    │   │       │   ├── Shiporder.class
    │   │       │   ├── Shiporder$Item.class
    │   │       │   └── Shiporder$Shipto.class
    │   │       └── package2
    │   │           ├── BookForm.class
    │   │           ├── BooksForm.class
    │   │           ├── ObjectFactory.class
    │   │           └── package-info.class
    │   ├── dir1
    │   │   └── shiporder.xsd
    │   └── dir2
    │       └── books.xsd
    └── generated-sources
        ├── xjc
        │   └── META-INF
        │       └── sun-jaxb.episode
        ├── xjc1
        │   └── com
        │       └── stackoverflow
        │           └── package1
        │               ├── ObjectFactory.java
        │               └── Shiporder.java
        └── xjc2
            └── com
                └── stackoverflow
                    └── package2
                        ├── BookForm.java
                        ├── BooksForm.java
                        ├── ObjectFactory.java
                        └── package-info.java
    

    Which seems to be the expected result.

提交回复
热议问题