Jaxb2 Maven 插件无法从 xsd 文件生成 java

Jaxb2 Maven Plugin failed to generate java from xsd file

我不明白official document。即使我按照这个例子,我仍然会出错。当我执行命令"mvn clean compile"时,显示如下错误:

Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:xjc (xjc) on project zTestJaxb: : MojoExecutionException: NoSchemasException -> [Help 1]

环境: mac, jdk8, eclipse Mars

项目目录

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>com</groupId>
<artifactId>zTestJaxb</artifactId>
<version>0.0.1-SNAPSHOT</version>


<build>
    <pluginManagement>
        <plugins>
            <!-- If we e.g. execute on JDK 1.7, we should compile for Java 7 to get 
                the same (or higher) JAXB API version as used during the xjc execution. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.3.1</version>
            <executions>
                <execution>
                    <id>xjc1</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- The package of your generated sources -->
                <packageName>com</packageName>

            </configuration>
        </plugin>
    </plugins>
</build>

检查您配置为 JDKJRE 的项目工作区,因为您的 pom 目标设置为 XJCXJC 将出现在您的 java/Jdk/bin 中。如果您使用的是 eclipse goto preferences --> java --> Installed JREs 在此处添加路径 JDK.