注入错误:org.jvnet.mjiip.v_2.XJC2Mojo java.lang.NoClassDefFoundError:com / sun / xml / bind / api / ErrorListener

时间:2015-08-26 05:25:11

标签: java spring-mvc maven-3 pom.xml

我正在使用maven将我的WSDL文件转换为Java类,但是当我提供以下Jar时:-org.jvnet.jaxb2.maven2 ---> maven-jaxb2-plugin version 0.8.3 / 0.12.3 但我收到以下错误

    [INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SOAPSpring 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.glassfish.jaxb:jaxb-runtime:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.glassfish.jaxb:jaxb-xjc:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] 
[INFO] --- maven-jaxb2-plugin:0.12.3:generate (generate) @ SOAPSpring ---
[WARNING] Error injecting: org.jvnet.mjiip.v_2.XJC2Mojo
java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener
    at java.lang.ClassLoader.defineClass1(Native Method)

我的POM文件看起来像......

<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>SOAPSpring</groupId>
<artifactId>SOAPSpring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SOAPSpring</name>
<description>SOAPSpring</description>

<properties>
    <jaxb2.plugin.version>0.8.3</jaxb2.plugin.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>${jaxb2.plugin.version}</version>
    </dependency>
    <!-- <dependency>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin-core</artifactId>
        <version>0.12.3</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.2.8</version>
    </dependency> -->
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>${jaxb2.plugin.version}</version>
            <executions>
                <execution>
                    <id>generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <packageName>com.exide.pensionWSDL</packageName>
                <wsdl>true</wsdl>
                <xmlschema>false</xmlschema>
                <schemaFiles>pension.wsdl</schemaFiles>
                <schemaDirectory>${project.basedir}/src/main/resources
                </schemaDirectory>
                <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
                <clearOutputDir>true</clearOutputDir>
            </configuration>
        </plugin>
    </plugins>
</build>

3 个答案:

答案 0 :(得分:3)

使用JRE而不是JDK时遇到了同样的错误。 我建议你确保使用JDK。

此致

答案 1 :(得分:1)

由于不兼容,也许您使用的JDK与您想象的不同。

如果使用的是Mac,请将JDK更改为1.8:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8` 

答案 2 :(得分:0)

我有同样的错误,按照AurélienPupier的建议,我检查了Java版本,但是$ JAVA_HOME为空,并且'java -version'命令向我显示Java 11版本而不是jdk 1.8。 所以我搜索了jdk版本1.8的位置,并使用上面的链接将其注册在$ JAVA_HOME变量中: enter link description here