Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 658
Roman Avatar asked Dec 08 '22 04:12

Roman


2 Answers

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:

  • Where to place and how to read configuration resource files in servlet based application?
like image 87
BalusC Avatar answered Dec 09 '22 17:12

BalusC


Put it in WEB-INF/classes. That is part of the classpath.

like image 43
Kees de Kooter Avatar answered Dec 09 '22 18:12

Kees de Kooter