Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split server.xml of apache tomcat into several separate files?

I use apache tomcat 7 to run a lot ofo virtual hosts on a single machine, I insert a Host tag for every virtual host in server.xml, so I can manage them in a centralized manner.
But now, after adding a lot of host tags, server.xml became so large & I'm seeking for a way to put every virtual host related tags in a separated xml file (exactly same that apache does for httpd.conf & virtual host management). e.g I make a separate xml file for every host & put all of them into a directory & force tomcat to load them!
Any Idea???

like image 470
Ehsan Khodarahmi Avatar asked May 04 '12 06:05

Ehsan Khodarahmi


People also ask

What is the server server XML configuration file in Tomcat?

The server. xml file is Tomcat's main configuration file, and is responsible for specifying Tomcat's initial configuration on startup as well as defining the way and order in which Tomcat boots and builds. The elements of the server.

What is Clustering in Tomcat?

Tomcat clustering is a group of Tomcat instances that are connected. An instance of Tomcat is an independent system. Clustering instances of Tomcat makes them interconnected. Tomcat instances in a Tomcat cluster are often referred to as a node.

What is jvmRoute?

jvmRoute. A routing identifier for this Tomcat instance. It will be added to the session id to allow for stateless stickyness routing by load balancers. The details on how the jvmRoute will be included in the id are implementation dependent.


1 Answers

The following should work but doesn't due to a Tomcat bug. I've fixed the bug in trunk (r1333827) and 7.0.x (r1333829) and the fix will be included in Tomcat 7.0.28 onwards. I could have sworn that this worked previously. It may be that the xml parser in the JVM has been tightened up at some point and that this will still work with older JVM versions but I haven't tested that.

You can use XML entities - one for each host. For example:

Insert the following just before the <server> element:

<!DOCTYPE server-xml [
  <!ENTITY host1 SYSTEM "host1.txt">
]>

The contents of host1.txt is the host element you want to define:

<Host>
  ...
</Host>

And then you insert this into server.xml inside the <engine> element like this:

<engine ...>
  &host1;
</engine>

Repeat for as many hosts as you need.

like image 166
Mark Thomas Avatar answered Oct 04 '22 06:10

Mark Thomas