WEB-INF path for files

I have a web application with configuration files in \WEB-INF\etc\config. This folder contains several property files and one xml. I need to configure the xml path in a single property file. After you configure this file to create an object during service startup, this object reads the properties from the file. Thus, this object must know the path to all the files described in the properties file. How can I describe the correct path in a property file if the property file and xml file are in the same directory?

Thank.

+3
source share
1 answer

, . ClassLoader#getResource() InputStream ClassLoader#getResourceAsStream().

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream("filename.xml");

, , ( ) XML.

, , - (, /WEB-INF), ServletContext#getResource() ServletContext#getResourceAsStream(), . ServletContext XML.

+5

Source: https://habr.com/ru/post/1776247/


All Articles