I am attempting to use jaxb2:xjc to generate domain java files form multiple .xsd files. The following is the build portion of my pom.xml file:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>xjc-atom-schema</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<clearOutputDir>true</clearOutputDir>
<outputDirectory>${project.basedir}/src/main/java/org.greenbuttonalliance.gba_sandbox/common/model/atom</outputDirectory>
<packageName>org.greenbuttonalliance.gba_sandbox.common.model.atom</packageName>
<sources>
<source>${project.basedir}/src/main/resources/atom.xsd</source>
</sources>
</configuration>
</execution>
<execution>
<id>xjc-energy-schema</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<clearOutputDir>true</clearOutputDir>
<outputDirectory>${project.basedir}/src/main/java/org.greenbuttonalliance.gba_sandbox/common/model/energy</outputDirectory>
<sources>
<source>${project.basedir}/src/main/resources/usage.xsd</source>
</sources>
<packageName>org.greenbuttonalliance.gba_sandbox.common.model.energy</packageName>
</configuration>
</execution>
<execution>
<id>xjc-retailcustomer-schema</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<clearOutputDir>true</clearOutputDir>
<outputDirectory>${project.basedir}/src/main/java/org.greenbuttonalliance.gba_sandbox/common/model/retailcustomer</outputDirectory>
<sources>
<source>${project.basedir}/src/main/resources/retailcustomer.xsd</source>
</sources>
<packageName>org.greenbuttonalliance.gba_sandbox.common.model.retailcustomer</packageName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am able to successfully execute mvn clean install but when I attempt to perform mvn jaxb2:xjc I receive the following error message:
Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:3.2.0:xjc (default-cli) on project common: : MojoExecutionException: NoSchemasException
The pom build portion above is in the common sub-directory and is intended to be used as a library jar for the other sub-directories shown in my project directory structure:
The mvn jaxb:xjc command is being executed in the common sub-directory.
Any assistance would be greatly appreciated.
I have tried several project organizations and was able to finally get the mvn install to work by moving the .xsd files to the common sub-directory’s resource folder rather than having them in a schema folder within the resource directory.
I’ve executed the mvn jaxb2:xjc command with the -X diagnostic option. According to the output, Jaxb2 is using the default output directory although the outputDirectory is overridden by the org.codehaus.mojo plugin configuration contents. Does this mean the real issue is that the xjc is not properly processing the pom.xml file in the common sub-directory and is really looking at another pom.xml file?
The short goal jaxb2:xjc
can only be user with single configuration since it is executed with default-cli
id (see mvn output and plugin execution when run with normal clean install
and with only jaxb2:xjc
)
See related issue on another similar plugin : https://github.com/highsource/jaxb-tools/issues/520#issuecomment-1987970784
Another tip out of initial question : you should generate sources outside the src/main/java
directory but more in something like target/generate-sources/xjc-XXX
with XXX
being different for each different execution.
2