【问题标题】:How to Reference Local XSD File By Relative Path如何通过相对路径引用本地 XSD 文件
【发布时间】:2017-07-14 15:35:03
【问题描述】:

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

【问题讨论】:

    标签: java xsd ehcache xsi


    【解决方案1】:

    认为我的问题是 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 正确/轻松地引用它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      相关资源
      最近更新 更多