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

xytpbqjk  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(582)

这是关于如何将eclipse配置为与“ehcache”一起使用的后续内容,并且在如何正确引用本地xmlschema文件中有一个绝对路径的示例?
自从 xsd 文件不再托管,我从存档中下载了一个副本。我已将该文件放在我的资源目录中,并希望在我的资源目录中引用它 xsi:schemaLocation 从我的项目的相对路径。我们有windows和mac开发人员,所以绝对路径约定 file:///c:/project/foo 不起作用。
相对路径的另一个替代方法是,如果有一种方法可以引用windows和mac的系统属性,那么我可以做两个条目,比如 file:///$HOME/workspace/foo .
我的mac上的项目存在于 ~/workspace/foo 回家的回声给了我回家的路。
我的 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上的文件?e、 g.以下情况不起作用:

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
r1wp621o

r1wp621o1#

我认为我的问题是webapp目录可能对resources文件夹没有可见性。
我这么说是因为基于对以下堆栈溢出问题的阅读,相对路径的内容看起来应该是非常简单的:xml文件和xml模式的本地副本,以及如何在xml文档中使用本地机器上的模式
然后,我尝试强制引用,以防它是具有部署目录或类路径的内容,但以下所有操作都失败了:

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

相关问题