将 maven-jaxb-plugin 与 eclipse 和 m2e 一起使用时缺少 ErrorListener

Posted

技术标签:

【中文标题】将 maven-jaxb-plugin 与 eclipse 和 m2e 一起使用时缺少 ErrorListener【英文标题】:ErrorListener missing when using maven-jaxb-plugin with eclipse and m2e 【发布时间】:2016-03-14 09:42:39 【问题描述】:

我已经为插件“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

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

这是我的 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>

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

【问题讨论】:

我现在完全迷路了。我试过这个 pom.xml: 我现在完全迷路了。我尝试使用这个 pom.xml: 1. 导入到新的 Eclipse(Mars) 工作区 2. 在新的 Eclipse(Mars) 工作区中从头开始构建 3. 在新的 Eclipse(Kepler) 工作区中使用新的初始本地从头开始构建我在 Eclipse UI 中使用“generate-sources”失败的所有三个示例的存储库,但行命令“mvn generate-sources”工作正常。 提供于org.glassfish.jaxb:jaxb-core 谢谢,但是使用它并不会改变 Eclipse 行为中的任何内容。这似乎是一个 Eclipse 问题;但如果是这样;它可能已经为社区所知。错误说异常被抛出“在 org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:168)” 现在在具有自己本地存储库的另一台计算机上使用相同的 pom。但是在 Eclipse 中,pom 仍然被标记为错误,因为缺少类 ErrorListener。我现在很确定 Eclipse 和/或 m2e 插件确实存在问题。已将全部 依赖项替换为 org.glassfish.jaxbjaxb-core2.2.11 现在;结果相同。任何人都可以通过将我的 pom.xml 用于新的 Maven 项目来确认我的问题吗? 【参考方案1】:

将插件更新到版本 0.13.3 可解决此问题。

【讨论】:

【参考方案2】:

我通过从我的 Eclipse 首选项(Java > 已安装的 JRE)中删除所有 JRE 并仅将选定的 JDK 保留在那里解决了这个问题。即使没有选择 JRE,它们仍然会导致问题并且必须被删除。我能够将 JRE 留在我的系统上。 这篇文章很有帮助:http://diggingthroughcode.blogspot.ca/2016/05/trouble-with-maven-jaxb2-plugin-and.html

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

【讨论】:

对于 jaxb2-maven-plugin 2.3.1 和 STS 3.9.0.RELEASE 构建 ID:201707061823 平台:Eclipse Oxygen (4.7.0) 也可以。但我需要直接从控制台运行 maven。我认为是 Eclipse 或 Eclipse 插件问题。【参考方案3】:

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

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

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

【讨论】:

添加后更新项目,需要这样做answer【参考方案4】:

同样的问题 - 当我降低版本时解决了它。

发件人:

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

收件人:

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

编辑:

我尝试了其他所有方法:

-从 Eclipse 中删除所有 JRE

-用JDK启动Eclipse

EDIT2:

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

【讨论】:

这会停止错误,但不会创建 hello.wsdl。【参考方案5】:

你可以试试

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

【讨论】:

【参考方案6】:

我也遇到过类似的问题:

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

在我的例子中,这是由于在 Java 8 项目中使用了 Java 10。切换到正确的 Java 版本即可解决。

【讨论】:

【参考方案7】:

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

【讨论】:

以上是关于将 maven-jaxb-plugin 与 eclipse 和 m2e 一起使用时缺少 ErrorListener的主要内容,如果未能解决你的问题,请参考以下文章

ECl@SS学习笔记采纳的国际标准与信息模型

ECl@SS学习笔记采纳的国际标准与信息模型

HPCC-ECL 逻辑运算符 - 为啥 OR 不短路?

csharp 检查TCM URI是否为ECL项。 (SDL Tridion 2013中的ECL API)

csharp 检查TCM URI是否为ECL项。 (SDL Tridion 2013中的ECL API)

如何在 HPCC / ECL 中将 SET 转换为 DATASET?