Jaxb2 target not being called

I am using maven-jaxb2-plugin to generate some classes from xsd. It is defined in the child pom like this:

<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 that jaxb2 is not called from mvn install or mvn compile or mv generate-sources. If I call mvn jaxb2: generate (as target name) the classes are generated OK. I've looked at some questions here and used the answers provided, but I still can't see anything. Thank.

+3


source to share


3 answers


Disclaimer: I am the author maven-jaxb2-plugin

.

It looks like you are only configuring the plugin in pluginManagement

, but not using it in your part build

.

This is how it should look:



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

      

A few other comments on your config:

  • 0.8.0

    - a very old version, 0.12.3

    is an actual one.
  • With modern Maven, you no longer need to configure maven-compiler-plugin

    with source

    / target

    version 1.6

    .
  • Do not useforceRegenerate

    .
  • Consider using bind files instead generatePackage

    .
  • The current version jaxb2-basics

    is 0.9.2.
+6


source


I ran into an error related to this plugin and Eclipse Maven integration.

Most searches for an answer have been fruitless, but often lead to this topic. So, I'm going to post this issue and workaround here, for any others who come across this.

When using the plugin maven-jaxb2-plugin: 0.12.3 correctly in maven on the command line - in Eclipse the source generation will fail with the following error:

Default execution target org.jvnet.jaxb2.maven2: maven-jaxb2-plugin: 0.12.3: generation failed: A required class was missing during execution org.jvnet.jaxb2.maven2: Maven-jaxb2-plugin: 0.12.3: generate: com / sun / xml / binding / api / ErrorListener

Various attempts to add jar files that contain the class it was looking for would simply result in another class missing, going down the hell jar file bunny hole and mis-matched classes that weren't resolvable.



I don't know if the problem is the problem that is broken in the Eclipse / M2E integration, or if the problem is in the maven-jaxb2-plugin dependency stack.

But the solution is to start Eclipse itself (not the JREs / JDKs installed in eclipse) with the JDK, not the JRE.

The easiest way is to add the -vm option 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...

      

+4


source


Update to version 0.13.2 + Kudos to @lexicore for comment below

+1


source







All Articles