I use web fragments (servlet 3 spec) and thus can load e.g. META-INF/resources/access.xml
file which is in a library in /WEB-INF/lib/
of my WAR via ServletContext.getResourceAsStream("access.xml")
.
Doing the same with ServletContext.getRealPath("access.xml")
doesn't work (=> null
).
The spec states:
The
getRealPath
method takes aString
argument and returns aString
representation of a file on the local file system to which a path corresponds. Resources inside theMETA-INF/resources
directory of JAR file must be considered only if the container has unpacked them from their containing JAR file when a call togetRealPath()
is made, and in this case MUST return the unpacked location.
My container (Tomcat) didn't unpack the jars, this seems to be the problem? How can Tomcat unpack the jars. Should I unpack the jars when packaging the WAR?