如果使用类似org.jvnet.jaxb2.maven2:maven-jaxb2-plugin
xsd文件解析的插件,则从jdk7升级到jdk8时会遇到此异常:
org.xml.sax.SAXParseException; systemId: file:/D:/Work/my/schema.xsd; lineNumber: 27; columnNumber: 133; schema_reference: Failed to read schema document 'CoreComponentsTechnicalSpecification-1p0.xsd', because 'file' access is not allowed due to restriction set by the accessExternalSchema property.
您如何使该插件与jdk8一起使用?
这个问题有相同的根本原因是这一个。有两种方法可以解决此问题:
设置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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句