問題描述
這是 如何配置 Eclipse 以使用的后續內容`ehcache` 并且在 如何正確引用本地 XML Schema 文件?
由于不再托管 xsd
文件,我從存檔中下載了它的副本.我已將該文件放在我的資源目錄中,并希望在我的 xsi:schemaLocation
中從我的項目的相對路徑中引用它.我們有 windows 和 mac 開發人員,所以像 file:///c:/project/foo
這樣的絕對路徑約定是行不通的.
Since the xsd
file is not longer being hosted, I downloaded a copy of it from the archive. I've put the file in my resource directory and would like to reference it in my xsi:schemaLocation
from a relative path of my project. We have both windows and mac developers, so an absolute path convention like file:///c:/project/foo
won't work.
相對路徑的另一種替代方法是,如果有一種方法可以引用 windows 和 mac 的系統屬性,那么我可以執行 2 個條目,例如 file:///$HOME/workspace/foo
.
Another alternative to relative path would be if there is a way to reference system properties for both windows and mac, then I could do 2 entries like file:///$HOME/workspace/foo
.
我的 Mac 上的項目存在于 ~/workspace/foo
中,$HOME 的 echo 給出了我的主路徑.
My project on my mac exists in ~/workspace/foo
and echo of $HOME gives my home path.
我的spring-cache.xml
存在于./src/main/webapp/WEB-INF/spring/
我的 ehcache-spring-1.2.xsd
存在于 ./src/main/resources/
以下是我嘗試過但沒有成功的一些:
The following are some that I've tried without success:
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 上的文件?例如以下方法無效:
I also seem to have issues getting it to reference the file from absolute path too, so perhaps there is a different way to reference the file on mac? e.g. The following did not work:
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
推薦答案
認為我的問題是 webapp 目錄可能無法查看資源文件夾.
Think my issue was that the webapp dir may not have visibility to the resources folder.
我這樣說是因為基于對以下堆棧溢出問題的閱讀,看起來相對路徑的東西應該非常直截了當:帶有 XML Schema 本地副本的 XML 文件 和 如何在 XML 文檔中使用本地機器上的 Schema
I say this because based on the reading of the following stack overflow questions, it looks like the relative path stuff should be pretty straigh forward: XML File with local copy of XML Schema and How to use Schema that is on local machine in XML document
然后我嘗試暴力破解引用,以防它與部署目錄或類路徑有關,并且以下所有操作都失敗了:
I then tried to brute force the references, in case it was something with deploy directory or class path, and all of the following failed:
../../../../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
However by moving the xsd file from ./src/main/resources/
to ./src/main/webapp/WEB-INF/spring/
I was then able to reference it correctly/easily by just ehcache-spring-1.2.xsd
這篇關于如何通過相對路徑引用本地 XSD 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!