Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm pretty new to Tomcat in general, so please point out if got anything wrong.

My question is regarding updates to already deployed apps, using the Tomcat manager. But first thing first. I'm using the META-INF/Context.xml for storing connection info for the database connections, so this is unique to every server the application is deployed to. I'm not sure if this is optimal but it's the only way I know.

So, when updating the application, it's important that this file doesn't get modified, because I don't want to have to go in and remake all changes every time I update my app.

For updating, I'm using the Tomcat Manager, and I've tried different approaches but everything seems to build on the process of undeploy, then deploy the new version. This way, the Context.xml gets removed/replaced by an empty Context.xml file.

So my question is basically, how do I update a running webapp, and at the same time having the Context.xml left untouched?

Btw, I'm running Tomcat 6.0.24.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

The setup up I'm currently working with has multiple contexts running the same webapp and each context has different database settings (similar to your setup except each context is running on a different server).

Instead of including the context.xml file in META-INF you can create a context.xml specifically for each instance on each server and put it in the $TOMCAT_ROOT$/conf/Catalina/localhost. When Tomcat starts the context any settings in the Catalina/localhost/context.xml will override those set in your web app (either through your WEB-INF/web.xml file or your META-INF/context.xml file).

We have had some small issues with this however were Parameters defined in the Catalina/localhost/context.xml are not properly overriding the ones defined in the web app but this is easily resolved by adding the override attribute to the Parameter node like so:

<Parameter name="foo" value="bar" override="1"/>

The docs for tomcat contexts describes a lot of this in more detail.

share|improve this answer
    
This seems to work. Will play with it later tonight. If I could I would've voted you up but apparently you needed 15 rep before one could do that, thanks though. –  Kristoffer Mar 26 '10 at 8:36
    
what I'm finding though is the file in conf/Catalina/localhost/<appname>.xml gets overwritten on every redploy. I want to know how to stop this. –  Michael Wiles Apr 19 '12 at 13:15
    
@mwiles Depending on the platform you are running tomcat on you could try removing tomcat's write permissions on the files and see if that helps. I typically store the context file elsewhere on the system and then use symlinks and haven't had any problems. –  Kevin Loney Apr 25 '12 at 19:22
    
@KevinLoney yes that is something I think I could do, thanks. –  Michael Wiles Apr 26 '12 at 8:19
add comment

My aproach:

        // In debug there are no context
        // In production is de WAR / Context name 
        String database = servletContext.getContextPath();
        database = database.replace("/", "");
        if (database.isEmpty())
            database = "<my_default_context_name_only_debug>";

        getLogger().info("Database: " + database);

        dataSource = (DataSource) dataSourceCtx.lookup("jdbc/" + database);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.