0

The JavaEE documentation for ServletContext.getRealPath() says:

Resources inside the /META-INF/resources directories of JAR files bundled in the application's /WEB-INF/lib directory must be considered only if the container has unpacked them from their containing JAR file, in which case the path to the unpacked location must be returned.

This method returns null if the servlet container is unable to translate the given virtual path to a real path.

When will a container unpack these resources? From what I can see, my Tomcat doesn't do that. Can I force a container to unpack these resources? Or is this implementation dependent?

phant0m
  • 16,595
  • 5
  • 50
  • 82
  • What are you trying to achieve. You most probably shouldn't use getRealPath() in the first place. – JB Nizet Feb 25 '17 at 10:35
  • @JBNizet You're probably right. I'm working with a legacy application consisting of thousands of JSPs and other resource files. I'm trying to cut down the build time by splitting it into multiple modules and move the resources into JARs. This way, building the application consists of copying a couple of JARs around which is nearly instant, rather than waiting minutes for the thousands of files to be moved. However, the application tries to access some of the resources directly over the file system (i.e. list a directory of resources). – phant0m Feb 25 '17 at 10:48
  • @JBNizet I've found [this](http://stackoverflow.com/questions/3923129/get-a-list-of-resources-from-classpath-directory) to work around the resources issue, but still looking into all options such that I don't need to locate every file access and rewrite it accordingly. – phant0m Feb 25 '17 at 10:49
  • 1
    @JBNizet I'm aware that this is basically an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – phant0m Feb 25 '17 at 10:50

0 Answers0