Java 读取不在classes dir下的war文件中的资源

Java 读取不在classes dir下的war文件中的资源,java,war,Java,War,我有一个具有以下结构的web应用程序: WEB-INF |-classes -- This is empty |-templates |-abc.properties |- xyz.properties |-lib |-internal.jar (all classes of our application) |- other jars 这些被捆绑成一场战争 我想读取WEB-INF/templates中存在的文件中的

我有一个具有以下结构的web应用程序:

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中的一个类执行。基本上,它们在类路径上

我试图通过以下方式获取资源,但它无法搜索。 {code} 1.


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

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

你使用的服务器是什么?你使用的是哪台服务器?例如:tomcat、jboss……我正在使用jetty服务器,但这不起作用。我想ServletContext是获取webapp私有资源所必需的。我是在一个普通的类中完成的,我可能需要以某种方式获取servlet上下文。
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream is = classLoader.getResourceAsStream("WEB-INF/templates/abc.properties");