How to generate java classes into source folder using jaxb2-maven-plugin?
Asked Answered
M

1

19

I use jaxb2-maven-plugin to generate java classes. There is plugin properties:

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <id>xjc</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- The package of your generated sources -->
                <packageName>com.bcap.me.JaxB</packageName>
                <sources>
                    <source>src/main/resources/xsds/pos.xsd</source>
                </sources>
            </configuration>
        </plugin>

After running mvn clean compile the plugin creates classes in the target\classes\com\bcap\me\JaxB directory. But i need to have classes in the source folder (package): src\main\java\com\bcap\me\JaxB How to do this?

UPDATE I add outputDirectory property, but i am not sure about the correctness of this approach:

<!--<packageName>com.bcap.me.JaxB</packageName>-->
<outputDirectory>src/main/java/com/bcap/me/JaxB</outputDirectory>

UPDATE

I solved my case like:

  <execution>
                        <id>xjc_pos</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <!-- The package of your generated sources -->
                            <packageName>com.bcap.me.JaxB</packageName>
                            <outputDirectory>src/main/java</outputDirectory>
                            <sources>
                                <source>src/main/resources/xsds/pos.xsd</source>
                            </sources>
                            <generateEpisode>false</generateEpisode>
                            <clearOutputDir>false</clearOutputDir>
                        </configuration>
                    </execution>

Thanks to @ulab

Mange answered 14/2, 2017 at 12:11 Comment(5)
I suppose you should provide only outputDirectory src/main/java as the rest is generated from the package name.Authenticity
I'm curious, what is use of clearOutputDir here ?Internationalist
@Mange Did you solve this issue? .. if yes, how?Zina
Specify <outputDirectory>src/main/java</outputDirectory>Mange
does this work with Java11 ? suggest upgrading plugin to 2.5.0Tigon
Z
3

You could use following maven plugin

       <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>target/generated-sources/xjc</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Zina answered 14/2, 2017 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.