Example:
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources/dir1</schemaDirectory>
<schemaIncludes>
<include>schema1.xsd</include>
</schemaIncludes>
<generatePackage>schema1.package</generatePackage>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources/dir2</schemaDirectory>
<schemaIncludes>
<include>schema2.xsd</include>
</schemaIncludes>
<generatePackage>schema2.package</generatePackage>
</configuration>
</plugin>
</plugins>
What happened:
Maven executes the the first plugin. Then deletes the target folder and creates the second package, which then is visible.
I tried to set target/somedir1 for the first configuration and target/somedir2 for the second configuration. But the behavior does not not change? Any ideas? I do not want to generate the packages directly in the src/main/java folder, because these packages are genereated and should not be mixed with manual created classes.
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 thetarget/generated-sources/<tool>convention for generated sources so that they will be imported in your favorite IDE automatically. I also recommend to declare severalexecutioninstead of declaring the plugin twice (and to move theconfigurationinside eachexecutionelement):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.javaWhich seems to be the expected result.