2017-03-08 106 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