JAXB maven plugin does not generate classes

I am trying to generate java files from XSD, but the code below does not generate. If I uncomment outputDirectory, it works, but delete the folder first. adding clearOutputDir = false also doesn't create 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> 

I get a message:

 [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. 
+5
source share
1 answer

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.

+6
source

Source: https://habr.com/ru/post/1242446/


All Articles