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

时间:2017-07-14 15:35:04

标签: java xsd ehcache xsi

这是对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

1 个答案:

答案 0 :(得分:2)

认为我的问题是webapp目录可能无法查看资源文件夹。

我之所以这样说是因为基于以下堆栈溢出问题的阅读,看起来相对路径的东西应该非常直观:XML File with local copy of XML SchemaHow 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

正确/轻松地引用它
相关问题