2017-03-08 178 views
0

运行mvn clean install时出现以下错误,无法访问外部文件。accessExternalDTD属性忽略目录文件

schema_reference: Failed to read schema document 'xml.xsd', because 'http' access is not allowed due to restriction set by the accessExternalSchema property. 

这种行为是打算作为我希望我的资源是本地的。但是,目录变更不应该避免这个错误?或者我的配置有问题吗?

部分POM文件:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>jaxb2-maven-plugin</artifactId> 
    <version>1.6</version> 
    <executions> 
     <execution> 
      <id>xjc</id> 
      <goals> 
       <goal>xjc</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <catalog>${project.basedir}/catalog.xml</catalog> 
     <schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory> 
     <outputDirectory>${project.basedir}/src/main/java</outputDirectory> 
     <clearOutputDir>false</clearOutputDir> 
    </configuration> 
</plugin> 
<plugin> 
    <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>file</value> 
      </property> 
      <property> 
       <name>javax.xml.accessExternalDTD</name> 
       <value>file</value> 
      </property> 
     </properties> 
     <outputFile/> 
    </configuration> 
</plugin> 

目录文件:

<!DOCTYPE catalog 
    PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> 
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> 
    <rewriteSystem systemIdStartString="http://www.w3.org/XML/1998/namespace" rewritePrefix="www.w3.org"/> 
</catalog> 

回答

1

经过大量的实验后,我发现mye目录是错误的。采用

<property> 
    <name>javax.xml.accessExternalSchema</name> 
    <value>file</value> 
</property> 
<property> 
    <name>javax.xml.accessExternalDTD</name> 
    <value>file</value> 
</property> 

掉了我改变了我的目录中catalog.cat文件,表格的catalog.xml,这样的:

REWRITE_SYSTEM "http://www.w3.org" "www.w3.org" 
REWRITE_SYSTEM "http://docs.oasis-open.org" "docs.oasis-open.org" 
REWRITE_URI "http://docs.oasis-open.org/wsn" "docs.oasis-open.org/wsn" 
REWRITE_URI "http://docs.oasis-open.org/wsrf" "docs.oasis-open.org/wsrf" 

上述特性也与此目录的工作,但我因为使用了工作目录,所以maven只要目录中的路径是正确的就不会获取任何外部模式。使属性过时。

+0

有了这些属性确实有帮助,因为maven在系统尝试不访问外部模式时抛出一个错误,并且很难通过阅读堆栈跟踪来捕获 – Bjerke

2

我有一个类似的错误,我尝试过许多解决方案,我发现,但对我来说是唯一可行的:

在插件标签此添加到您的POM

  <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <configuration> 
        <systemPropertyVariables> 
         <javax.xml.accessExternalSchema>all</javax.xml.accessExternalSchema> 
        </systemPropertyVariables> 
       </configuration> 
      </plugin> 

对不起,我的英语不好,我希望这会适合你

+0

不是我正在寻找的,我的问题是我想迫使maven intousing本地文件,而不是extarnal的,我现在已经在这个成功,想通过其他手段。然而,你的建议确实解决了错误信息! :) – Bjerke