In the documentation of Tomcat, the section about Defining a context lists the following options to define a context:
$CATALINA_BASE/conf/[enginename]/[hostname]/
directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.Option 1 is bad, because it means that one must hard code the values inside the application artifact and they cannot be easily changed.
Option 3 is actively discouraged by the documentation:
It is NOT recommended to place elements directly in the server.xml file.
This only leaves us with option 2, especially this is the only option if we would like to deploy the same application several times with different configurations (e.g. one for production, one for testing).
However the documentation does not explain, what [enginename]
or [hostname]
are supposed to be, or what they default to.
What are the default values for these and where can I change them?
TL;DR
[enginename]
is usually Catalina
and [hostname]
is usually localhost
.
Simple Explanation
In the default configuration that is shipped with Tomcat, the engine is configured in $CATALINA_HOME/conf/server.xml
, at the end of that file you will usually see something like this:
<Engine name="Catalina" defaultHost="localhost">
...
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
</Engine>
The name
property of <Engine>
element is the enginename
and the name
property of the <Host>
element is the hostname
.
Longer Explanation
The answer can be found in two places, by reading the Host and Engine pages of the Tomcat documentation.
For the <Engine>
element the interesting values are:
defaultHost:
The default host name, which identifies the Host that will process requests directed to host names on this server, but which are not configured in this configuration file. This name MUST match the name attributes of one of the Host elements nested immediately inside.
name:
Logical name of this Engine, used in log and error messages. When using multiple Service elements in the same Server, each Engine MUST be assigned a unique name.
For the <Host>
element it states:
name:
Usually the network name of this virtual host, as registered in your Domain Name Service server. Regardless of the case used to specify the host name, Tomcat will convert it to lower case internally. One of the Hosts nested within an Engine MUST have a name that matches the defaultHost setting for that Engine. See Host Name Aliases for information on how to assign more than one network name to the same virtual host.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With