tags:

views:

471

answers:

4

Hello!

I want to start Tomcat 6 with special configuration sometimes, not using the "server.xml". So I created another xml file named "server_test.xml". Now I want to tell tomcat to use this configuration. How is this done?

I found nearly nothing searching the web. Only that: "Use different server.xml file in Tomcat configuration: ./tomcat.sh start -f /var/tmp/server-${USER}.xml"

This is exactly what I want. Maybe this is working for linux systems but not for windows. Any ideas out there?

Sebastian

A: 

It doesn't look like there is a (documented) option you can pass to startup.sh or catalina.sh to change this.

Perhaps you can set server.xml as a symlink to the file you actually want to use, and just change the symlink prior to starting the server when you want to change it?

Otherwise you can play around with using different values of $CATALINA_HOME but this would require you to duplicate the entire directory structures.

matt b
A: 

tomcat.sh hasn't existed since 3.x and, to be honest, I don't recall it having '-f' option back then either.

You have two choices here:

A) You can setup multiple tomcat instances as described here and switch between them by pointing CATALINA_BASE to the one you want.

B) You can create multiple server.xml files named differently (e.g. server-1.xml, server-2.xml, etc...) and write a simple batch script that would copy the one you specify as command line argument to the actual server.xml and then start Tomcat.

ChssPly76
A: 

Put your app's special values in META-INF/context.xml and let Tomcat pick them up that way.

You shouldn't be mucking around with server.xml.

duffymo
Do explain how this will help with the original problem which was to start tomcat using different configurations. You're just delegating the whole thing to another level. And that's not even mentioning things like virtual hosts / clustering / what have you that can't be configured in app context.
ChssPly76
I re-read the original question, and I don't see any mention of virtual hosts or clustering or anything else. All I saw was a need to add deployment specific configuration, and that's what I answered. Yes, I am delegating it to another level, and I'd say it's the appropriate one. When I work, I'm not allowed to touch the server configuration, so I have to find a way to make it app specific. That's the way it's done on serious Java EE app servers like WebLogic and JBOSS.
duffymo
I'll ignore the "serious Java EE" remark (though it should never be used in the same sentence with "Weblogic") and let's assume that everything you want to configure can indeed be configured in `META-INF/context.xml`. My point was (and it still stands) that you did not answer the original question.
ChssPly76
Apparently you've never used WebLogic. Too bad.
duffymo
+1  A: 

I've got it. I took me the half night, but it works :)

At first I also thought of symbolic links, but under windows it's not a thing you would like to use. My second thought was modifying catalina.bat, but that's not that easy. And different CATALINA_HOME's is not what I really want. So what have I done? I've provided the server.xml as a parameter to catalina.bat.

"catalina.bat start -config \conf\server_test.xml" - Nice and easy :)

You can have a lot of server configuration files and provide the one you need to the start and stop script. The tricky thing was that the Catalina class gives you the wrong usage information: "usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { start | stop }". But if you exchange the parameters and first provide "start" or "stop" and then the "-config ..." argument, everything works. Also very nice is that you can use this solution the create different run configuration in IntelliJ IDEA. I have one where the tomcat connects to a local database and one connecting to a development database. For each I have a different server.xml.

I hope this helps.

Regards, Sebastian

seb