[英]How to receive correct class loader for jar in web application?
I have application mywebapp. 我有应用程序mywebapp。 This application depends from myjarconfig.jar.
此应用程序取决于myjarconfig.jar。 File myjarconfig.jar contains file config.xml.
文件myjarconfig.jar包含文件config.xml。 To take resource I use code:
要获取资源,我使用代码:
InputStream confStream = ClassLoader.class.getResourceAsStream("/conf/config.xml");
But I always receive null. 但是我总是收到null。 When I look in debugger - I see that ClassLoader is mywebapp.
当我查看调试器时-我看到ClassLoader是mywebapp。 Why it is not jar file?
为什么不是jar文件? What need to check?
需要检查什么? Thanks.
谢谢。
如果您的jar位于WEB-INF / lib,容器的类路径,引导类路径等位置,则应使用
Thread.currentThread().getContextClassLoader().getResourceAsStream("/conf/config.xml")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.