I have a directory to which a process uploads some .pdf files. This process is out of my control.
I need to make those files available through the website using Tomcat.
I have a directory /var/lib/tomcat5/webapps/test1 available to the web and I can see the files in it with a browser.
So, I created a symbolic link pointing at the directory with the .pdf files: /var/lib/tomcat5/webapps/test1/files/, but I can’t see anything in that directory.
How can I enable symlinks in the test1 directory only? I don’t want to enable symlinks everywhere, just so that directory with .pdf files is available to the web.
There are a few problems with the solution of creating a
META-INF/context.xmlthat contains<Context path='/myapp' allowLinking='true'>The biggest issue is that if a
conf/context.xmlexists, theallowLinkingin the<Context>there takes precedence over a<Context>in aMETA-INF/context.xml. And if the in theconf/context.xmldoes not explicitly defineallowLinking, that’s the same as sayingallowLinking='false'. (see my answer to a context precedence question)To be sure that your app allows linking, you have to say
<Context override='true' allowLinking='true' ...>.Another issue is that the
path='/myapp'is ignored in aMETA-INF/context.xml. To prevent confusion, it’s best to leave it out. The only timepathin a<Context>has any effect is in theserver.xml, and the official Tomcat docs recommend against putting<Context>s in aserver.xml.Finally, instead of a
myapp/META-INF/context.xmlfile, I recommend using aconf/Catalina/localhost/myapp.xmlfile. This technique means you can keep the contents of yourMETA-INFclean, which is the guts of your webapp — I don’t like to risk mucking about in the guts of my webapp. 🙂