views:

1913

answers:

2

Hi,

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 available to the web, with the browser I can see files in it : /var/lib/tomcat5/webapps/test1

So I created a symbolic link to point 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 sym links in the "test1" directory only? I don't want to enable sym links everywhere, just so that directory with pdf files is available to the web.

Thanks

+3  A: 

Create a context.xml file in a WEB-INF directory in your web app containing:

<?xml version="1.0" encoding="UTF-8"?>

<Context path="/myapp" allowLinking="true">

</Context>

more here: http://www.isocra.com/2008/01/following-symbolic-links-in-tomcat/

Loki
Yes, all I had to do was create a context.xml file : /var/lib/tomcat5/webapps/test1/META-INF/context.xmlThat link was very helpful. Thank you.
jeph perro
Thanks for this. Any idea how to configure tomcat (6) to always follow symlinks?
Tom Martin
The same techniques work for Tomcat 6.0 to follow symlinks.
netjeff
A: 

There are a few problems with the solution of creating a WEB-INF/context.xml that contains <Context path="/myapp" allowLinking="true">

The biggest issue is that if a conf/context.xml exists, the allowLinking in the <Context> there takes precedence over a <Context> in a META-INF/context.xml. And if the in the conf/context.xml does not explicitly define allowLinking, that's the same as saying allowLinking="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 a WEB-INF/context.xml. To prevent confusion, it's best to leave it out. The only time path in a <Context> has any effect is in the server.xml, and the official Tomcat docs recommend against putting <Context>s in a server.xml.

Finally, instead of a myapp/WEB-INF/context.xml file, I recommend using a conf/Catalina/localhost/myapp.xml file. This technique means you can keep the contents of your WEB-INF clean, which is the guts of your webapp -- I don't like to risk mucking about in the guts of my webapp. :-)

netjeff