Simple question: In Tomcat7, what\'s the difference between using extraResourcePaths and aliases to access an directory outside the application?
I can use either of
This is the result of having multiple different ways of pulling in resources that aren't part of a WAR or exploded directory. Frankly it is a mess long overdue a clean-up. The 'overlay' (or whatever it ends up being called) feature proposed for Servlet 3.1 (i.e. Tomcat 8) has prompted a major clean-up. All the current implementations will be unified into a single implementation. It isn't pretty though, and it is going to take a while to complete.
Aliases are treated as external to the web application resources. The DirContext checks aliases before it checks its internal resources. Hence when you request the real path you get the original.
If you use extraResourcePaths they are treated as part of the web application resources. It looks like Eclipse has triggered a copy of application resources to the work directory. This is usually done to avoid file locking. Since the extraResourcePaths are treated as part of the webapp, they get copied too and getRealPath() reports the copied location since that is where Tomcat is serving the resources from.
After investigating further, I found this difference.
The results of this Java code is different. I still don't know why.
String path = getServletContext().getRealPath("/images");
Using extraResourcePaths, path is below, which is a folder under where Eclipse explodes my web app and not a valid directory.
C:\Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\Eclipse_Project\images
Using aliases, path is below and is what I actually need.
D:\path\to\images
Now if someone could actually explain this. :-)