在 eclipse 和 m2e 中使用 maven-jaxb-plugin 时缺少 ErrorListener

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34173363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:58:30  来源:igfitidea点击:

ErrorListener missing when using maven-jaxb-plugin with eclipse and m2e

javaeclipsemavenspring-bootjaxb

提问by Ulrich

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:

我已经为插件设置了一个项目“ org.jvnet.jaxb2.maven2:maven-jaxb2-plugin"。它可以工作,但我不喜欢 Eclipse 编辑器中为“pom.xml”显示的错误消息。消息指出:

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.

pom 和由此整个项目被标记为错误。

Here is my pom.xml:

这是我的 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>Hymanson-core</artifactId>
            <groupId>com.fasterxml.Hymanson.core</groupId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <artifactId>Hymanson-annotations</artifactId>
            <groupId>com.fasterxml.Hymanson.core</groupId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <artifactId>Hymanson-databind</artifactId>
            <groupId>com.fasterxml.Hymanson.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?

我的“ mvn validate”命令没有说明任何错误,并且声称的 ErrorListener 提供了工件“ com.sun.xml.bind:jaxb-core”。正如已经说过的,在运行项目以生成源时,它工作正常。有没有人运行这个插件并且可以分享他的 pom.xml ?

回答by Mahmoud Saleh

Updating Plugin to version 0.13.3fixes this issue.

将插件更新到0.13.3 版修复了这个问题。

回答by Darren Reimer

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

我通过从我的 Eclipse 首选项(Java > 已安装的 JRE)中删除任何 JRE 并只将选定的 JDK 留在那里解决了这个问题。即使未选择 JRE,它们仍会导致问题,必须将其删除。我能够将 JRE 留在我的系统上。这篇文章很有帮助: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).

[更新] 另一位同事刚刚遇到了这个问题,对他来说,关键因素似乎是使用哪种 Java 来运行 Eclipse。它也不会使用 JAVA_HOME 配置的内容,而是使用第一个可用的 Java 运行时。他从他的系统中删除了所有 jres,只留下了一个 jdk,这解决了问题。我认为关键因素是 eclipse 是使用 jre 还是 jdk 运行。当我解决这个问题时,我确实从我的系统中删除了一个 jre,这可能是 eclipse 一直在使用的。由于缺少这个 jre,它切换到 jdk,即使我有其他 jres 可用。如果您不想从系统中删除 jres,您可以指定 eclipse 应该使用的 java 运行时(如何使用不同的 java 版本运行 eclipse?)。如果未指定任何内容,eclipse 将确定要使用的 java 运行时(找出 JVM Eclipse 在什么上运行)。

回答by leftbit

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

这个问题是由 eclipse 运行在 JRE 而不是 JDK 上引起的。

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

编辑您的 eclipse.ini 并指向合适的 JDK - 例如

-vm C:/Program Files (x86)/Java/jdk1.7.0_55/bin/javaw.exe

回答by Lazar Lazarov

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

- 从 Eclipse 中删除所有 JRE

-Starting Eclipse with JDK

- 使用 JDK 启动 Eclipse

EDIT2:

编辑2:

Check your .m2folder. Find the problematic jar and check its size. In some situations Maven could have not download the dependency properly and the .jarcan exist but have 0kbsize. IF SO: Delete the .jarand let Maven download it again.

检查您的.m2文件夹。找到有问题的 jar 并检查其大小。在某些情况下,Maven 可能没有正确下载依赖项,并且.jar可以存在但有0kb大小。如果是这样:删除.jar并让 Maven 再次下载它。

回答by Vivek Padigela

You can try

你可以试试

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

回答by Tmarty

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

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.

就我而言,这是由于在 Java 8 项目中使用了 Java 10。切换到正确的 Java 版本解决了它。

回答by Nicolas Ordonez Chala

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

我遇到了同样的问题,我知道这可能有点傻,但请尝试检查您在 pom.xml 中提供的 url 中的所有资源(wsdl 和 xsd)是否可用