TCH
TCH

Reputation: 604

Generate both beans and META-INF in the same folder jaxb2-maven-plugin 2.3

I'm using jaxb2-maven-plugin version 2.3 to generate jaxb java beans.

The point is that I want to be able to generate both the beans and the META-INF/ folder inside the same directory, such as src/main/java/x/y/z. Otherwise at least not generating the META-INF/ folder under src/main/java.
Is that possible ? If I don't set a <packageName> then a default package (defined in .xsd file) is applied to the generated beans.
Here is my current configuration in pom.xml file :

<build>
    <plugins>
        <plugin>
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>jaxb2-maven-plugin</artifactId>
             <version>2.3</version>
             <executions>
                 <execution>
                 <id>schema-x</id>
                 <goals>
                     <goal>xjc</goal>
                 </goals>
                 <configuration>
                     <xjbSources>
                         <xjbSource>src/main/resources/path/to/file.xjb</xjbSource>
                     </xjbSources>
                     <sources>
                         <source>src/main/resources/path/to/file.xsd</source>
                     </sources>
                     <packageName>x.y.z</packageName>
                     <outputDirectory>${basedir}/src/main/java</outputDirectory>
                     <clearOutputDir>false</clearOutputDir>
                </configuration>
            </execution>
        </plugin>
    </plugins>
</build>

Upvotes: 0

Views: 381

Answers (1)

Laurent Schoelens
Laurent Schoelens

Reputation: 2848

This applies to jaxb2-maven-plugin but also to any plugin that generates java sources : you should genetate the output in the build directory.

If not and generating in src folder like here, you'll then have to commit / push generated files and have a non stable build.

The documentation of the plugin says about outputDirectory :

Corresponding XJC parameter: d.

The working directory where the generated Java source files are created.

Type: java.io.File Required: Yes Default: ${project.build.directory}/generated-sources/jaxb

The maven compiler and the IDE is then capable to get this directory (or any subdirectory in generated-sources by convention) and you'll be able to use generated source code in your own code

Upvotes: 1

Related Questions