2017-07-14 283 views
2

这是一个跟进How to Configure Eclipse to Work with `ehcache`并有绝对路径的How to reference a local XML Schema file correctly?如何引用本地XSD文件通过相对路径

为例由于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

认为我的问题是,Web应用程序目录可能无法查看资源文件夹。

我这样说是因为基于以下堆栈溢出问题的阅读,它看起来像的相对路径的东西应该是相当straigh前锋:XML File with local copy of XML SchemaHow to use Schema that is on local machine in XML document

然后我试图蛮力引用,万一这是一件与deploy目录或类路径中,所有的失败后的:

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