I’ve put a properties file within src/main/resources in my JSF project.
How do I get a handle to it? I understand that EL doesn’t work within a backing bean.
Note: The file is in src/main/resources – NOT src/main/webapps/resources, so the following doesn’t work:
FacesContext context = FacesContext.getCurrentInstance();
File value = context.getApplication().evaluateExpressionGet(context, "#{resource['resources:email.properties']}", File.class);
It’s thus in the classpath. You can just use
ClassLoader#getResourceAsStream()to get anInputStreamout of it. Assuming thatsrcis the classpath root and thatmain/resourcesis the package:Alternatively, if it’s supposed to be specific to the webapp and thus isn’t supposed to be overrideable by a file on the same path elsewhere in the classpath which has a higher classloading precedence (e.g. in appserver’s lib or the JRE’s lib), then use
ExternalContext#getResourceAsStream()instead.As to the
#{resource}syntax, this is indeed specifically for CSS/JS/image resources placed in/resourcesfolder of public web content. See also How to reference CSS / JS / image resource in Facelets template?