如何通过相对路径引用本地XSD文件 [英] How to Reference Local XSD File By Relative Path
问题描述
这是如何配置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
T.解决方案:
但是,从 ./rc / main / resources /
移动xsd文件到 ./ 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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!