views:

3426

answers:

2

I am trying to use symbolic links in one of the applications I have running on Tomcat5. Thanks to some help from another StackOverflow question I was able to do it by creating a context.xml file in

/...myapplication/META-INF/context.xml

I am now trying to implement this on a production server. However, there are other applications running on it. And there is another context file

/...tomcat/conf/context.xml

It seems to me these are setting configurations server-wide to all applications. If I allowLinks in the conf/context.xml file, my symbolic links work. If I don't allowLinks in conf/context.xml, my application's symbolic links do not work, even though I have allowed them in the META-INF/context.xml

My question is, does the conf/context.xml control all applications? If I want symbolic links to work only in one application, do I need to remove the conf/context.xml and create new context files for each application? Or is there a way I can allow symbolic links in myapplication only?

+1  A: 

See my answer to the "Which Tomcat 5 context file takes precedence" question.

Regarding your specific allowLinks question, the value in conf/context.xml takes precedence by default. If you say nothing in your conf/context.xml, the default value is allowLinks="false" in your conf/context.xml.

If you want to change it only for your myapplication, trying to say <Context allowLinks="true" ...> in your META-INF/context.xml will have no effect because normally the conf/context.xml setting will take precedence.

But, if you say <Context allowLinks="true" override="true" ...> in your META-INF/context.xml, then all your <Context> settings in META-INF/context.xml will be highest precedence, overriding anything in conf/context.xml.

Finally, instead of a myapplication/WEB-INF/context.xml file, I recommend using a conf/Catalina/localhost/myapplication.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
+1  A: 

Just to add a point.

Usually th meta-inf/context.xml is copied to the conf/Catalina/localhost/myapplication.xml

When redploying a war file the conf/Catalina/localhost/myapplication.xml is deleted and a new one copied in as described above.

This can be a real pain. I like the idea of application specific context but I fail to see how having this in the meta-inf directory helps.

For Prod, UAT, etc this becomes a real pain.

So for anything server static but application specific it is better to put it in the conf/context.xml. Which has the negative that it holds context for several applications, touch one you inadvertently touch them all.