这个问题的根本原因与this one 相同。有两种方法可以解决这个问题:
设置 javax.xml.accessExternalSchema 系统属性:
如果您只是在本地构建,您可以将此行添加到 /path/to/jdk1.8.0/jre/lib 下名为 jaxp.properties 的文件(如果它不存在):
javax.xml.accessExternalSchema=all
如果您可能与其他人一起从事该项目,这将不起作用,特别是如果他们仍在使用 jdk7。您可以使用命令行上指定的系统属性运行您的 Maven 构建:
$mvn <target and options> -Djavax.xml.accessExternalSchema=all
您也可以使用插件为您设置系统属性:
<plugin>
<!-- Needed to run the plugin xjc en Java 8 or superior -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<id>set-additional-system-properties</id>
<goals>
<goal>set-system-properties</goal>
</goals>
</execution>
</executions>
<configuration>
<properties>
<property>
<name>javax.xml.accessExternalSchema</name>
<value>all</value>
</property>
<property>
<name>javax.xml.accessExternalDTD</name>
<value>all</value>
</property>
</properties>
</configuration>
</plugin>
也可以配置maven-jaxb2-plugin来设置属性:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<configuration>
<!-- Needed with JAXP 1.5 -->
<vmArgs>
<vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
</vmArgs>
</configuration>
</plugin>
设置目标版本:
如果不想使用系统属性,可以将maven-jaxb2-plugin设置为目标版本2.0:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>${maven.plugin.jaxb2.version}</version>
<configuration>
<args>
<arg>-target</arg>
<arg>2.0</arg>
</args>
</configuration>
</plugin>