问题
This is a follow up on How to Configure Eclipse to Work with `ehcache` and there is an example of absolute path in How to reference a local XML Schema file correctly?
Since the xsd
file is not longer being hosted, I downloaded a copy of it from the archive. I've put the file in my resource directory and would like to reference it in my xsi:schemaLocation
from a relative path of my project. We have both windows and mac developers, so an absolute path convention like file:///c:/project/foo
won't work.
Another alternative to relative path would be if there is a way to reference system properties for both windows and mac, then I could do 2 entries like file:///$HOME/workspace/foo
.
My project on my mac exists in ~/workspace/foo
and echo of $HOME gives my home path.
My spring-cache.xml
exists in ./src/main/webapp/WEB-INF/spring/
My ehcache-spring-1.2.xsd
exists in ./src/main/resources/
The following are some that I've tried without success:
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
I also seem to have issues getting it to reference the file from absolute path too, so perhaps there is a different way to reference the file on mac? e.g. The following did not work:
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:
Think my issue was that the webapp dir may not have visibility to the resources folder.
I say this because based on the reading of the following stack overflow questions, it looks like the relative path stuff should be pretty straigh forward: XML File with local copy of XML Schema and How to use Schema that is on local machine in XML document
I then tried to brute force the references, in case it was something with deploy directory or class path, and all of the following failed:
../../../../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
The solution:
However by moving the xsd file from ./src/main/resources/
to ./src/main/webapp/WEB-INF/spring/
I was then able to reference it correctly/easily by just ehcache-spring-1.2.xsd
来源:https://stackoverflow.com/questions/45106799/how-to-reference-local-xsd-file-by-relative-path