JAXB maven插件不生成类 [英] JAXB maven plugin not generating classes

查看:173
本文介绍了JAXB maven插件不生成类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从XSD生成java文件,但下面的代码不会生成。如果我取消注释outputDirectory,它可以工作,但首先删除该文件夹。添加 clearOutputDir = false 也没有生成任何内容。

I am trying to generate the java files from the XSD, but the below code doesn't generate. If I uncomment outputDirectory, it works but delete the folder first. adding clearOutputDir = false is also not generating anything.

<build>
        <plugins>
            <!-- JAXB xjc plugin that invokes the xjc compiler to compile XML schema into Java classes.-->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- The package in which the source files will be generated. -->
                    <packageName>uk.co.infogen.camel.message</packageName>
                    <!-- The schema directory or xsd files. -->
                    <sources>
                        <source>${basedir}/src/main/resources/xsd</source>
                    </sources>
                    <!-- The working directory to create the generated java source files. -->
                    <!--<outputDirectory>${basedir}/src/main/java</outputDirectory>
                    <clearOutputDir>false</clearOutputDir>-->
                </configuration>
            </plugin>
        </plugins>
    </build>

我收到消息:

[INFO] --- jaxb2-maven-plugin:2.2:xjc (default) @ service-business ---
[INFO] Ignored given or default xjbSources [/Users/aaa/development/workspace/infogen/infogen_example/service-business/src/main/xjb], since it is not an existent file or directory.
[INFO] No changes detected in schema or binding files - skipping JAXB generation.


推荐答案

首先,你应该从不,永远, src / main / java 中生成代码。生成的代码不应该受版本控制,并且可以随时删除,因为无论如何它都会被重新生成。

The first thing is that you should never, ever, generate code inside src/main/java. Generated code should not be version-controlled and can be deleted at any-time since it will be regenerated anyway.

生成的代码应始终位于 target ,Maven的构建目录。 jaxb2-maven-plugin 将生成类 target / generated-sources / jaxb 并且没有理由改变它。如果您正在使用Eclipse,则只需将此文件夹添加到构建路径中,方法是右键单击它并选择构建路径>使用源文件夹。

Generated code should always be located under target, the build directory of Maven. The jaxb2-maven-plugin will generate classes by default under target/generated-sources/jaxb and there's really no reason to change that. If you're using Eclipse, you just need to add this folder to the buildpath by right-clicking it and selecting "Build Path > Use a Source Folder".

运行Maven,你将用 mvn clean install 运行它:它将清理目标文件夹并从头开始重新生成所有内容:这导致了安全和可维护的构建。您会发现这将解决您的问题:由于生成的类在构建之前被删除,因此它们将在下一次构建期间正确地重新生成。

When running Maven, you will run it with mvn clean install: it will clean the target folder and regenerate everything from scratch: this leads to a safe and maintainable build. You'll find that this will solve your problem: since the generated classes are deleted before the build, they will be correctly re-generated during the next build.

当然,如果这个生成过程很长并且你不想每次都这样做,你可以用 mvn install 运行Maven并配置插件不要删除之前生成的通过设置 clearOutputDir false 。但请注意,虽然构建速度稍快,但如果更新后,您可能无法检测XSD中的后续错误。

Of course, if this generation process is long and you don't want to do it each time, you can run Maven with just mvn install and configure the plugin not to remove the previously generated classes by setting clearOutputDir to false. But do note that, while the build will be slightly faster, you may not detect subsequent errors in your XSD if they are updated.

这篇关于JAXB maven插件不生成类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆