The first thing you should never generate code inside src/main/java . The generated code should not be versioned and can be deleted at any time, as it will be regenerated anyway.
The generated code should always be in target , the Maven build directory. jaxb2-maven-plugin will generate default classes in target/generated-sources/jaxb and there is no reason to change it. If you use Eclipse, you just need to add this folder to the build path by right-clicking on it and choosing Build Path> Use Source Folder.
When you start Maven, you run it with mvn clean install : it will clean the target folder and regenerate everything from scratch: this leads to a safe and supported build. You will find that this solves your problem: since the generated classes are deleted before the build, they will be recreated correctly during the next build.
Of course, if this generation process is long, and you do not want to do it every time, you can run Maven only with mvn install and configure the plugin to not delete previously created classes by setting clearOutputDir to false . But note that although the build will be a little faster, you will not be able to detect subsequent errors in the XSD if they are updated.
source share