Tomcat configuration
Main files concerning tomcat configuration
On a deployed tomcat instance, these files can be found at
/opt/tomcat/conf
references: tomcat docs
conf/ - catalina.policy - catalina.properties - logging.properties - server.xml - tomcat-users.xml - web.xml - context.xml
server.xml
this is the main config file. located in the conf
dir of
installed tomcat configure Resources
such as jdbc, messge
brokers etc within GlobalNamingResources
:
conf/
- catalina.policy
- catalina.properties
- logging.properties
- server.xml
- tomcat-users.xml
- web.xml
- context.xml
server.xml
this is the main config file. located in the conf
dir of
installed tomcat configure Resource
s such as jdbc, messge
brokers etc within GlobalNamingResources
:
<Server ...
...
<GlobalNamingResources>
<Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource"
username="user"
password="password"
uri="jbdc:mysql://localhost:3306/db"
...
/>
</GlobalNamingResources>
/Server>
web.xml
deployment descriptor for a web application. Defines servlets, filters
and other components. during development typically located in
WEB-INF
dir
<web-app ...
<display-name>my web app</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>MyAppServlet</servlet-name>
<serlet-class>com.gallaghern.MyAppServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyAppServlet</servlet-name>
<url-pattern>/myapplicationname</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>jdbc/db</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
resource-ref
element refers to the
jdbc/db
data source defined in server.xml
context.xml
defines database connections, JNDI resources and other configurations
There exists a server context and a context for each web application.
The server context is found in the conf
dir and is used
to define global resources shared across many web applications.
An application context is located in the META-INF
dir and
is used to define resources specific to that application.
<Context>
<Resouce name"jdbc/db"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/db"
username="user"
password="password"
...
/>
</Context>
The above context.xml
contains a
Resource
element which specifies connection parameters
for a mqsql database including jdbc driver class name, url, username,
password and connection pooling settings.
A context.xml
file might also detail a
ResourceLink
element:
<Context>
<ResourceLink name="jdbc/db"
global="jdbdc/db"
type="javax.sql.DataSource"
/>
</Context>
which refers to an external resource called jdbc/db
.
global
specifies the JNDI name of the resource - defined
in the server context and referenced in the application context
catalina.properties
contains the global config settings located in conf
dir
setenv.sh
set environment variables for tomcat. typically java options. located
in bin
dir
#!/bin/sh
export JAVA_OPTS="-xms512m -Xmx1024"
export CATALINA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8"
...
logging.properties
defines log levels, log file location and log format
note
During development these files could be located in different locations depending on the codebase. Some options such as JDBC connectivity or runtime settings might be set programatically.