Apparently you placed the resource in physically the wrong location.
The ExternalContext#getResourceAsStream()
, which delegates in case of servlet containers under the covers to ServletContext#getResoruceAsStream()
, has its root in the web content of the WAR (the parent folder of /WEB-INF
and /META-INF
folders, thus the files therein are also available this way), and the /META-INF/resources
folder of all JARs in /WEB-INF/lib
. In case of a JSF web application it are usually XHTML, CSS, JavaScript and image files.
In other words, it returns web resources. It doesn't return a disk file system resource, for that you need new FileInputStream()
instead. It also doesn't return a classpath resource, for that you need ClassLoader#getResourceAsStream()
instead. The classpath has its root in a.o. /WEB-INF/classes
, all JARs in /WEB-INF/lib
, and some VM/server-configured folders depending on the runtime environment.
In an usual web content file structure, the resource file has to be placed exactly here in order to obtain it the desired way:
WebContent
|-- META-INF
|-- WEB-INF
| |-- faces-config.xml
| `-- web.xml
|-- myFile.png <-- Here.
: