Edit "server.xml" in Tomcat without restarting server?

I'd start by saying that the question is not completely correctly made, as it is quite possible to actually edit the file without restarting Tomcat, but the changes are ignored by the running process.

The real question would be how to apply changes in server.xml without restarting Tomcat.

Gathering information from the startup process and the class-loader pages on Tomcat's online documentation, it is possible to understand this in more detail.

More specifically, it's described in serverStartup.txt and the UML diagram of the startup process and the relevant portions can be summarized as follows:

Sequence 1. Start from Command Line
  ...
Sequence 2. Process command line argument (start, startd, stop, stopd)
Class: org.apache.catalina.startup.Bootstrap (assume command->start)
What it does:
a) Catalina.setAwait(true);
b) Catalina.load()
    b3) createStartDigester()
        Configures a digester for the main server.xml elements
    b4) Load the server.xml and parse it using the digester
        Parsing the server.xml using the digester is an automatic
        XML-object mapping tool, that will create the objects defined
        in server.xml
        Startup of the actual container has not started yet.
    b6) Calls initialize on all components, this makes each object
        register itself with the JMX agent.

This happens after the creation of the Bootstrap classloader of the servlet engine (Catalina).

With this information, it's clear now when in the startup process the server.xml file is parsed, but it doesn't really answer the question of why it is required to restart Tomcat to apply changes to this file.

The answer is that some part of it can be modified dynamically at runtime using JMX. For this to be possible, the appropriate MBean has had to be registered (b6 step above), and also has to accept SET operations (some MBeans only have a GET interface).

In your specific case, there is no way to create and register a new Host at runtime because there's no provision for it, and this is the reason why you have to restart the Tomcat process to have the Bootstrap classloader instantiate that object and register it with JMX agent.

Afterwards, it is possible to modify that host from a JMX client such as the jconsole that comes bundled with any JDK.

Connect you jconsole to an JMX enabled Tomcat and browse the Host MBean to check all available attributes:

jconsole showing attributes of Host MBean

and check all the available operations (one of them shown below as an example):

jconsole showing an example operation on the Host MBean


No. Restart Required.

The Tomcat doc page for <Context> mentions:

…the main conf/server.xml file cannot be reloaded without restarting Tomcat.