从 Jar 中加载上下文
我需要一些澄清;我有一个我构建的 jar,并且在 jar 内部有一个我需要加载的自定义 application-context.xml
文件。我将文件加载到 jar 内的类中。当我设置此 application-context.xml 的 url 时,该目录是特定于我的 jar 的类路径,还是仍然是使用 jar- 的类路径的项目?
例如 --
Jar 的类路径:
src > main > META-INF > application-custom-context.xml
项目的类路径:
src > Libraries > myjar.jar > src > main > META-INF > application-custom-context.xml
我知道这些 url 不准确 :P -- 但是,在我的上下文创建中,我将遵循哪个目录结构。这都是理论上的。今天有人问我这个问题,我不知道如何回答。我认为如果你从 jar 中调用一个类,类路径应该相对于该 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 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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Spring 上下文的“路径”是相对于类路径的。如果该 jar 包含在您的类路径中(例如,位于 web-inf/lib 中),那么它将被视为位于您的项目中(web-inf/classes)。
换句话说,如果您的上下文文件位于 jar 文件内的“META-INF\spring\context.xml”中,则包含您的 jar 文件的任何人都可以以相同的方式引用它。
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.