如何使用 jaxb2-maven-plugin 将 java 类生成到源文件夹中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42225868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 06:28:22  来源:igfitidea点击:

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

javajaxbjaxb2-maven-plugin

提问by May12

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

我使用 jaxb2-maven-plugin 来生成 java 类。有插件属性:

<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 compilethe plugin creates classes in the target\classes\com\bcap\me\JaxBdirectory. But i need to have classes in the source folder (package): src\main\java\com\bcap\me\JaxBHow to do this?

运行mvn clean compile插件后,在target\classes\com\bcap\me\JaxB目录中创建类。但我需要在源文件夹(包)中有类:src\main\java\com\bcap\me\JaxB如何做到这一点?

UPDATEI add outputDirectoryproperty, but i am not sure about the correctness of this approach:

更新我添加了outputDirectory属性,但我不确定这种方法的正确性:

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

感谢@ulab

回答by Xstian

You could use following maven plugin

您可以使用以下 maven 插件

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