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,040,783
  • 362
  • 3,548
  • 3,513
Roman
  • 61,962
  • 88
  • 232
  • 324

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,040,783
  • 362
  • 3,548
  • 3,513
1

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

Kees de Kooter
  • 6,838
  • 5
  • 38
  • 44
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
  • 76,783
  • 33
  • 229
  • 231