JAXB maven plugin not generating classes

前端 未结 1 770

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 cle

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 09:23

    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.

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

    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.

    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.

    0 讨论(0)
提交回复
热议问题