I am using maven-jaxb2-plugin to generate some classes from xsd. It is defined in child pom as follows:
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
<executions>
<execution>
<id>jaxb2-generate</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<forceRegenerate>true</forceRegenerate>
<!-- Generate classes from XSD (XML Schema) using JAXB -->
<schemaDirectory>src/main/resources/com/reportcenter/settings/</schemaDirectory>
<generatePackage>com.reportcenter.settings</generatePackage>
<schemaIncludes>
<include>**/*.xsd</include>
</schemaIncludes>
<strict>false</strict>
<extension>true</extension>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.2</version>
</plugin>
</plugins>
<args>
<arg>-Xannotate</arg>
<arg>-XtoString</arg>
<arg>-Xcopyable</arg>
</args>
</configuration>
</plugin>
</plugins>
</pluginManagement>
The problem is the jaxb2 is not called from mvn install or mvn compile or mv generate-sources. If I call mvn jaxb2:generate (as the name of the goal) the classes are created OK. I looked at some questions here and used the answers provided, but I am still missing something. Thank you.
Disclaimer: I am the author of the maven-jaxb2-plugin
.
Seems like you only configure the plugin in pluginManagement
but don't actualy use it in your build
part.
This is how it should look like:
<project ...>
...
<build>
<plugins>
...
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
Few other comments on your configuration:
0.8.0
is a very old version, 0.12.3
is the actual one.maven-compiler-plugin
with source
/target
version 1.6
.forceRegenerate
.generatePackage
.jaxb2-basics
is 0.9.2.I ran into an error related to this plugin, and the Eclipse Maven integration.
Most searches for an answer were fruitless, but often lead to this thread. So, I'm going to post the issue, and a workaround here, for any others that run into it.
While using the maven-jaxb2-plugin:0.12.3 plugin correctly in maven on the command line - in Eclipse, source generation would fail with the following error:
Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate: com/sun/xml/bind/api/ErrorListener
Various attempts at adding jar files that contain the class it was looking for would just result in another class missing, going to a rabbit hole of jar file hell and mis-matched classes that wasn't resolvable.
I don't know if the problem here is something that is broken in the Eclipse / M2E integration, or if the problem is in the dependency stack of maven-jaxb2-plugin.
But the solution is to launch Eclipse itself (not the JREs / JDKs installed into eclipse) with a JDK, instead of a JRE.
The easiest way to do that is to add -vm parameter to your eclipse.ini file:
-startup plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
-vm C:\Program Files\Java\jdk1.8.0_31\bin\javaw.exe
--launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20150204-1316
-product
...snip...
Upgrade to version 0.13.2 + Kudos to @lexicore for the comment below
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With