How to get properties file from /WEB-INF folder in JSF?

Roman picture Roman · Jan 26, 2010 · Viewed 8.9k times · Source

I have some properties file in /WEB-INF. And I want to load it in a JSF managed bean. Is there any way to do that?

Answer

BalusC picture BalusC · Jan 26, 2010

Use either ExternalContext#getResource() or ExternalContext#getResourceAsStream() wherein you pass the webcontent-relative path.

E.g.:

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Properties properties = new Properties();
// ...
properties.load(externalContext.getResourceAsStream("/WEB-INF/file.properties"));

This delegates under the covers to ServletContext#getResource()/getResourceAsStream().

See also: