Loading context from within a Jar
I need some clarification; I have a jar that I built and inside of the jar it has a custom application-context.xml
file that I need to load. I load the file within a class inside of the jar. When I am setting the url of this application-context.xml, is the directory specific to my jar's classpath, or still the project that is using the jar-'s classpath?
For example --
Jar's 开发者_JAVA百科classpath:
src > main > META-INF > application-custom-context.xml
Project's classpath:
src > Libraries > myjar.jar > src > main > META-INF > application-custom-context.xml
I know these url's aren't accurate :P -- But, inside of my context creation, which directory structure would I follow. This is all theoretical. Somebody asked me this today, and I have no clue how to answer it. I would think that if you call a class from a jar, the classpath should be relative to the contents of that jar.. But, what I think is far from always right :)
The "path" to the Spring context is relative to the classpath. If the jar is included in your classpath (it's in web-inf/lib for example), then it would be treated just as if it was in your project (web-inf/classes).
In other words, if your context file is in "META-INF\spring\context.xml" inside your jar file, anyone who includes your jar file can reference it in the same manner.
精彩评论