15

I edited the "server.xml" file in Tomcat 8’s conf folder. I added a new Host tag for a new web site.

Must I restart the Tomcat server?

Can I get Tomcat to parse and apply the newly edited server.xml?

4
  • 2
  • @dawud Thanks for the link, but we’re talking about <Host>, not <Context>. May 30, 2015 at 22:14
  • 2
    Regardless, the important part is that server.xml is parsed once at startup. It can't be reloaded without a restart.
    – dawud
    May 30, 2015 at 22:17
  • @dawud Thanks. I see that mention now. I made this an Answer so I can close this Question. May 30, 2015 at 22:22

2 Answers 2

17

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

1
  • 1
    +1 for introducing me to JMX. Jan 22, 2016 at 19:36
11

No. Restart Required.

The Tomcat doc page for <Context> mentions:

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

3
  • 1
    Those upvotes should go to @dawud...no more comment. Poor answer for someone that said we’re talking about <Host>, not <Context>. -1 sorry, it is rare i do this, but there i have to...
    – krisFR
    May 31, 2015 at 1:49
  • 1
    @krisFR dawud was free to write an Answer at any time, then or now. Not everyone plays this game for up-votes. May 31, 2015 at 1:51
  • 1
    @krisFR , Basil Bourque I have added a more detailed answer to cover this in a more general way. Hope it's useful.
    – dawud
    May 31, 2015 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .