4

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Roman
  • 64,384
  • 92
  • 238
  • 332

3 Answers3

14

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

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

Kees de Kooter
  • 7,078
  • 5
  • 38
  • 45
0
     String path="/WEB-INF/list.properties";

    InputStream is=FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(path);
    InputStreamReader r = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(r);
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254