21

I have setup a project just for the plugin "org.jvnet.jaxb2.maven2:maven-jaxb2-plugin". It works but I don't like the error message displayed within the Eclipse editor for the "pom.xml". The message states:

Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate: com/sun/xml/bind/api/ErrorListener

The pom and by this the whole project ist marked to be in error.

Here is my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.gombers.lernen.jaxb</groupId>
    <artifactId>PlayWithJAXB</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <configuration>
                    <show>private</show>
                    <nohelp>true</nohelp>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <extension>true</extension>
                    <useDependenciesAsEpisodes>true</useDependenciesAsEpisodes>
                    <outputDirectory>target/generated-sources/jaxb</outputDirectory>
                    <packageName>de.gombers.lernen.jaxb.generated</packageName>
                    <schemaDirectory>src/main/resources</schemaDirectory>
                    <schemaFiles>Employee.xsd</schemaFiles>
                </configuration>
            </plugin>

        </plugins>


    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

        <!-- JAXB -->
        <dependency>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin-core</artifactId>
            <version>0.13.1</version>
        </dependency>
        <dependency>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb22-plugin</artifactId>
            <version>0.13.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-project</artifactId>
            <version>2.0.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-settings</artifactId>
            <version>2.0.9</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-container-default</artifactId>
            <version>1.0-alpha-9-stable-1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.7</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.7</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.7</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-jxc</artifactId>
            <version>2.2.7</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-xjc</artifactId>
            <version>2.2.7</version>
        </dependency>


        <!-- HELPERS -->
        <dependency>
            <groupId>de.gombers</groupId>
            <artifactId>BasicTools</artifactId>
            <version>1.0.0</version>
        </dependency>

        <!-- LOGGING -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.13</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.2</version>
        </dependency>

        <!-- JUNIT -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.8.4</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <!-- JSON converter -->
        <dependency>
            <artifactId>jackson-core</artifactId>
            <groupId>com.fasterxml.jackson.core</groupId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <artifactId>jackson-annotations</artifactId>
            <groupId>com.fasterxml.jackson.core</groupId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <artifactId>jackson-databind</artifactId>
            <groupId>com.fasterxml.jackson.core</groupId>
            <version>2.3.3</version>
        </dependency>

    </dependencies>
</project>

My "mvn validate" command does not state any error, and the claimed ErrorListener is provided with the artifact "com.sun.xml.bind:jaxb-core". And as already said, when running the project to generate sources it works fine. Has anybody running this plugin and can share his pom.xml?

JayC
  • 2,144
  • 8
  • 42
  • 77
Ulrich
  • 715
  • 2
  • 7
  • 25
  • I'm totally lost now. I tried with this pom.xml: – Ulrich Dec 09 '15 at 11:11
  • I'm totally lost now. I tried with this pom.xml: 1. import to a new Eclipse(Mars) Workspace 2. build from scratch within a new Eclipse(Mars) workspace 3. Build from scratch within a new Eclipse(Kepler) Workspace with a new initial local repository for all three of the samples I failed with "generate-sources" out of Eclipse UI, but line command "mvn generate-sources" works fine. – Ulrich Dec 09 '15 at 11:17
  • Provided in `org.glassfish.jaxb:jaxb-core`. – lexicore Dec 09 '15 at 12:37
  • Thank you, But using this doesn't change anything in Eclipse behaviour. It seems to be an Eclipse problem; but if so; it probably would have been known to the community already. The error says that the exception is thrown "at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:168)" – Ulrich Dec 09 '15 at 13:05
  • Used now the very same pom on a different computer with it's own local repository. But within Eclipse the pom is still marked being in error because class ErrorListener is missing. I'm now pretty surem there is really a problem with Eclipse and/or the m2e-plugin. Have replaced the whole bunch of dependencies by org.glassfish.jaxb jaxb-core 2.2.11 now; with the same result. Can anybody confirm my problem by using my pom.xml for a new Maven-Project? – Ulrich Dec 12 '15 at 09:52
  • I also got the same problem. I tried with ` org.glassfish.jaxb jaxb-core 2.2.11 ` but no luck. same error exists.. – Ramya Selvarani Feb 23 '16 at 05:58
  • this post doesn't have an answer. Anybody got lucky?? – Aditya Peshave Jun 02 '16 at 02:49

7 Answers7

27

Updating Plugin to version 0.13.3 fixes this issue.

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
10

I resolved this issue by removing any JREs from my Eclipse preferences (Java > Installed JREs) and only leaving the selected JDK there. Even though the JREs were not selected, they still cause the issue and have to be removed. I was able to leave the JREs on my system. This post was helpful: http://diggingthroughcode.blogspot.ca/2016/05/trouble-with-maven-jaxb2-plugin-and.html

[Update] Another coworker just ran into this and for him it seemed the critical factor was which Java was being used to run Eclipse. It won't use what JAVA_HOME is configured too, but the first Java runtime available. He removed all jres from his system and only left a jdk and that resolved the issue. I believe the critical factor is whether eclipse is running with a jre or a jdk. When I resolved the issue I did remove one jre from my system and this was likely what eclipse had been using. With this jre missing it switched to a jdk even though I had other jres available. If you don't want to remove jres from your system you can specify what java runtime eclipse should use (How to run eclipse with different java version?). If nothing is specified eclipse will determine the java runtime to use (Find out what JVM Eclipse is running on).

Community
  • 1
  • 1
Darren Reimer
  • 741
  • 8
  • 9
  • For jaxb2-maven-plugin 2.3.1 and STS 3.9.0.RELEASE Build Id: 201707061823 Platform: Eclipse Oxygen (4.7.0) work too. But I needed run maven directly from console.I think is a Eclipse or Eclipse pluging problem. – Sergio Sep 05 '17 at 19:29
5

This problem was caused by eclipse running on a JRE instead of a JDK.

Edit your eclipse.ini and point to a suitable JDK - for example

-vm C:/Program Files (x86)/Java/jdk1.7.0_55/bin/javaw.exe
leftbit
  • 848
  • 1
  • 7
  • 18
4

Same problem here - solved it when I decrease the version.

From :

            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.1</version>

To:

            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.8.1</version>

EDIT:

I tried everything else :

-Deleting all the JRE from Eclipse

-Starting Eclipse with JDK

EDIT2:

Check your .m2 folder. Find the problematic jar and check its size. In some situations Maven could have not download the dependency properly and the .jar can exist but have 0kb size. IF SO: Delete the .jar and let Maven download it again.

Lazar Lazarov
  • 2,412
  • 4
  • 26
  • 35
3

You can try

<build>
    <pluginManagement>
        <plugins>
            <plugin> ... </plugin>
            <plugin> ... </plugin>
                  ....
        </plugins>
    </pluginManagement>
</build>
0

I had a similar problem:

Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.3:generate failed: Prefix '' is already bound to ''

In my case this was due to using Java 10 on a Java 8 project. Switching to the correct Java version resolved it.

Tmarty
  • 477
  • 5
  • 10
0

I had the same problem, I know It could be kind of silly but try checking if the all resources (wsdl and xsd) are available in the url that you are giving in the pom.xml