这是对How to Configure Eclipse to Work with `ehcache`的跟进,并且在How to reference a local XML Schema file correctly?中有一个绝对路径的示例
由于不再托管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
最佳答案
认为我的问题是webapp目录可能对资源文件夹不可见。
我之所以这样说是因为,根据对以下堆栈溢出问题的阅读,看起来相对路径的东西应该很直接:XML File with local copy of XML Schema和How to use Schema that is on local machine in XML document
然后,我尝试强行引用,以防引用带有部署目录或类路径,并且以下所有操作均失败:
../../../../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
正确/轻松地引用它