来自xsd的maven-jaxb2-plugin类生成(版本错误)

时间:2015-07-03 06:30:09

标签: java xml maven xsd

我的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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.rajkishan</groupId>
<artifactId>RESTful-Swagger</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>

<name>RESTful-Swagger</name>

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.2.4.RELEASE</version>
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <start-class>com.rajkishan.Application</start-class>
</properties>

 <dependencies>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>com.mangofactory</groupId>
    <artifactId>swagger-springmvc</artifactId>
    <version>1.0.2</version>
</dependency>

</dependencies>

 <build>
<plugins>

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>

    <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>
            <configuration>
                <schemaDirectory>src/main/resources</schemaDirectory>
                <schemaIncludes>
                    <include>Greeting.xsd</include>
                </schemaIncludes>
                <generatePackage>com.rajkishan.xmlgen</generatePackage>
            </configuration>
        </plugin>

</plugins>

当我在&#34; Netbeans&#34;中使用maven构建时,这样可以正常工作。

但是,如果我在Eclipse Luna中使用它,它会给出错误;

  

目标org.jvnet.jaxb2.maven2的执行默认值:maven-jaxb2-plugin:0.12.3:生成失败:执行org.jvnet.jaxb2.maven2时缺少必需的类:maven-jaxb2-plugin:0.12 .3:generate:com / sun / xml / bind / api / ErrorListener

但如果我将版本更改为0.12.1,如下所示,则可行;

<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.12.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaDirectory>src/main/resources</schemaDirectory>
                <schemaIncludes>
                    <include>Greeting.xsd</include>
                </schemaIncludes>
                <generatePackage>com.rajkishan.xmlgen</generatePackage>
            </configuration>
        </plugin>

任何人都可以告诉我这里有什么不对吗?我错过了什么吗?

注意:我在eclipse中使用jdk1.8。

2 个答案:

答案 0 :(得分:5)

我遇到了同样的问题。 Eclipse是用jre而不是jdk启动的。在改变eclipse以开始使用jdk后它运行正常......

希望它有所帮助。

答案 1 :(得分:1)

添加以下依赖项,然后重试 -

<dependency>
   <groupId>com.sun.xml.bind</groupId>
   <artifactId>jaxb-impl</artifactId>
   <version>2.2.11</version>
</dependency>