seb
seb

Reputation: 281

How to start Tomcat with a specific server.xml under Windows?

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?

Upvotes: 8

Views: 13626

Answers (3)

ChssPly76
ChssPly76

Reputation: 100806

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.

Upvotes: 0

seb
seb

Reputation: 281

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

Upvotes: 20

matt b
matt b

Reputation: 140051

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.

Upvotes: 0

Related Questions