2015-11-06 53 views
13

如果你使用像org.jvnet.jaxb2.maven2:maven-jaxb2-plugin一個插件來分析你的XSD文件,您可以從JDK7升級時遇到這種異常jdk8:的SAXParseException與jdk8和Maven的JAXB2-插件

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一起工作?

+0

你見過[這](HTTP: //stackoverflow.com/questions/23011547/webservice-client-generation-error-with-jdk8)? – Stefan

+0

@Stefan絕對,但是這個問題雖然具有相同的根本原因,但與使用Maven插件生成代碼無關。 –

回答

34

此問題與this one具有相同的根本原因。有兩種方法來解決這個問題:

設置javax.xml.accessExternalSchema系統屬性:

如果你只在本地建立,您可以加入這一行的jaxp.properties文件命名(如它不存在)下/path/to/jdk1.8.0/jre/lib:

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> 
+0

嗨Niel, 我正在使用JRE1.8.0_111,我找不到文件jaxp.properties。任何想法 ? – Aguid

+0

不知道,對不起@AyadiAkrem –

+0

properties-maven-plugin與1.6版本的jaxb2-maven-plugin配合使用 – richardhell