如何通过相对路径引用本地XSD文件

这是关于如何配置Eclipse以使用`ehcache`的后续内容,并且在如何正确引用本地XML架构文件中有一个绝对路径示例?

由于不再托管xsd文件,我从存档中下载了它的副本。 我把文件放在我的资源目录中,并希望从我项目的相对路径中的xsi:schemaLocation引用它。 我们有windows和mac开发人员,因此像file:///c:/project/foo这样的绝对路径约定将不起作用。

相对路径的另一种替代方法是,如果有一种方法可以引用windows和mac的系统属性,那么我可以执行2个条目,如file:///$HOME/workspace/foo

我的mac上的项目存在于~/workspace/foo ,$ HOME的echo给出了我的主路径。

我的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文件与XML Schema的本地副本以及如何使用XML文档中的本地机器上的Schema

然后我尝试强制引用,如果它是部署目录或类路径,并且以下所有失败:

 ../../../../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 

解决方案:

但是,通过将./src/main/resources/的xsd文件移动到./src/main/webapp/WEB-INF/spring/我可以通过ehcache-spring-1.2.xsd正确/轻松地引用它