我有在tomcat上运行的Web应用程序。我想在
中加入一些资源resources.jar
e.g。
configuration.xml
但是当我尝试时:
new File("/conf/configuration.xml")
没找到。
可能是我应该用另一种方式配置路径?
答案 0 :(得分:2)
在Web应用程序中运行时,应使用ContextClassLoader
:
Thread.currentThread().getContextClassLoader().getResource("/conf/configuration.xml");
或
Thread.currentThread().getContextClassLoader().getResourceAsStream("/conf/configuration.xml");
第一个将返回URL
,第二个将返回InputStream
。