Thursday, October 9, 2014

Handling Symbolic Links in Tomcat in Linux

Tomcat by default does not allows files to be accessed via symbolic links or symlinks. For example 
you have an application context foo. The chance is you will have a foo directory sitting in webapps 
which contains all the things about the application. However you want to have access to a report.pdf 
file generated in other part of system, let's say at /etc/reports/report.pdf. The file is generated with some frequency so you would like to put a symblolic link to the generated file. The symbolic link can be given by

ln -s report.pdf /etc/reports/report.pdf

By default, Tomcat does not allows linking to the symbolic links. To achieve that you neeed to change the context.xml file at <Tomcat Installation Directory>/conf/context.xml

<Context allowLinking="true">


The change requires a restart of Tomcat.

Individual context.xml can be put at:
  • In META-INF/context.xml . Not a good practise as this may override local changes.
  • In individual file at <Tomcat Installation Directory>/conf/Catalina/localhost/foo.xml . As the context is foo in this case, the file name is put as foo. This is the right way to do as this does not requires chagnes to the web application. 

Tomcat does not recommends to make allowLinking= true in Windows environment or any OS which is not case sensitive.

For more details on Context file of Tomcat, check this.

No comments:

Post a Comment