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 websi
Adding following line into conf/context.xml enables softlinks for me on apache tomcat 8.5+
<Resources allowLinking="true" cachingAllowed="true" cacheMaxSize="100000">
There are 4 places where Context can live.
In case of tomcat 8 allowlinking attribute should be specified not in Context but in Resources tag. My tomcatdir/conf/context.xml looks like this
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<Resources allowLinking="true" cachingAllowed="true" cacheMaxSize="100000" />
</Context>
This solution works fine for me now. But I want to share also the mistake I had done before coming to this solution.
I had defined Resources both in tomcatdir/conf/server.xml and in tomcatdir/conf/context.xml. And allowLinking="true" was set only in tomcatdir/conf/server.xml.
What I found was that if you do not specify allowLinking it is equal to setting it to false. So I removed Resources tag from server.xml and left it only tomcatdir/conf/context.xml with the allowLinking="true" attribute in it.
This works different in Tomcat 8+
http://tomcat.apache.org/migration-8.html
<Resources allowLinking="true" />
I made it in this other way. I edit this other configuration file: apache-tomcat-7.0.33/conf/server.xml In Host tag I added:
<Context path="/data" docBase="C:\datos" debug="0" reloadable="true" crossContext="false"/>
So, you can acces via: http://localhost/data
Create a context.xml file in a META-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/
There are a few problems with the solution of creating a META-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 META-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/META-INF/context.xml
file, I recommend using a conf/Catalina/localhost/myapp.xml
file. This technique means you can keep the contents of your META-INF
clean, which is the guts of your webapp -- I don't like to risk mucking about in the guts of my webapp. :-)