2017-07-14 275 views
2

這是一個跟進How to Configure Eclipse to Work with `ehcache`並有絕對路徑的How to reference a local XML Schema file correctly?如何引用本地XSD文件通過相對路徑

爲例由於xsd文件不再主持過程中,我下載了一個副本來自檔案。我已將該文件放在我的資源目錄中,並希望從我的項目的相對路徑中的xsi:schemaLocation中引用它。我們有Windows和Mac開發人員,因此像file:///c:/project/foo這樣的絕對路徑約定將不起作用。

另一種相對路徑的替代方法是,如果有一種方法可以引用windows和mac的系統屬性,那麼我可以做2個條目,如file:///$HOME/workspace/foo

我在我的Mac上的項目存在於~/workspace/foo和$ HOME的回聲給我的家鄉道路。

spring-cache.xml存在./src/main/webapp/WEB-INF/spring/

ehcache-spring-1.2.xsd存在./src/main/resources/

下面是一些我沒有成功嘗試:

 file:///$HOME/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd 
     file:///./src/main/resources/ehcache-spring-1.2.xsd    
     file:///../../../../resources/ehcache-spring-1.2.xsd 
     file:///../../../../resources/ehcache-spring-1.2.xsd 
     ../../../../resources/ehcache-spring-1.2.xsd 
     file://../../../../resources/ehcache-spring-1.2.xsd 
     file://$HOME/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd 
     file://./src/main/resources/ehcache-spring-1.2.xsd    
     file://../../../../resources/ehcache-spring-1.2.xsd 

我似乎也有它越來越來的問題也從絕對路徑引用文件,所以也許有不同的方式來引用mac上的文件?例如以下沒有工作:

file:///Users/me/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd 
file:////Users/me/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd 
file://Users/me/workspace/foo/src/main/resources/ehcache-spring-1.2.xsd 

回答

1

認爲我的問題是,Web應用程序目錄可能無法查看資源文件夾。

我這樣說是因爲基於以下堆棧溢出問題的閱讀,它看起來像的相對路徑的東西應該是相當straigh前鋒:XML File with local copy of XML SchemaHow to use Schema that is on local machine in XML document

然後我試圖蠻力引用,萬一這是一件與deploy目錄或類路徑中,所有的失敗後的:

../../../../resources/ehcache-spring-1.2.xsd 
../../../resources/ehcache-spring-1.2.xsd 
../../resources/ehcache-spring-1.2.xsd 
../resources/ehcache-spring-1.2.xsd 
./resources/ehcache-spring-1.2.xsd 
../ehcache-spring-1.2.xsd 
./ehcache-spring-1.2.xsd 

解決辦法:

然而,通過將xsd文件從./src/main/resources/移動到./src/main/webapp/WEB-INF/spring/,然後我可以正確/容易地僅通過ehcache-spring-1.2.xsd