读取不在类目录下的war文件中的资源

时间:2015-04-14 07:59:34

标签: java war

我的网络应用程序具有以下结构:

WEB-INF
 |-classes
    -- This is empty
 |-templates
         |-abc.properties
         |- xyz.properties    
 |-lib
     |-internal.jar (all classes of our application)
     |- other jars

这些捆绑为战争

我想读取WEB-INF / templates中存在的文件中的属性。 注意:上述操作需要从internal.jar中的一个类进行。基本上他们在classpath

我尝试了以下来获取资源,但无法搜索到它。 {码} 1.

final InputStream inputStream = FileTemplateDaoImpl.class.getClassLoader().getResourceAsStream(resourcePath)
{/code}
where i tried following as resource path:
 templates/abc.properties
 /WEB-INF/templates/abc.properties

1 个答案:

答案 0 :(得分:0)

我在这里假设,一旦打开war文件,这些* .properties文件在WEB-INF/templates下可用,现在是试图利用这些属性文件的类,请尝试下面提到的代码块。

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream is = classLoader.getResourceAsStream("WEB-INF/templates/abc.properties");