saplingPro
saplingPro

Reputation: 21329

difference between context.xml and server.xml?

what is the difference between context.xml of Tomcat and server.xml of Tomcat ? If I want to add a tag like :

    <Resource name="jdbc/MyDs" auth="Container" type="javax.sql.DataSource"
     driverClassName="org.apache.derby.jdbc.ClientDriver"
     url="jdbc:derby://localhost:1527/my_database;create=true"
     username="me" password="me" maxActive="20" maxIdle="10" maxWait="-1" />

where should I add it ?

Upvotes: 11

Views: 15198

Answers (3)

GlaIZier
GlaIZier

Reputation: 835

Tomcat web application has a bunch of configs called deployment descriptors which can be separated in two groups: server-dependent (context.xml) and server-independent (web.xml).

server.xml - stores on server side and describe the general configuration of Tomcat server. This file is the only one for a one Tomcat server.

context.xml - can be stored on server side (conf/) or be embedded in a web app (META-INF/). This file contains server-dependent configuration like DataSources provided by Tomcat server.

web.xml - can be stored on server side (conf/) or be embedded in a web app (WEB-INF/). This file contains server-independent configuration like servlet mappings.

Context.xml and web.xml on a server-side in the Tomcat conf/ directory are used to provide the default behavior of Tomcat, like default servlet mappings. Thus we have one server.xml per server and a pair context.xml/web.xml of files per a web application. If you want to share configuration between several application you should use server.xml (e.g. like it is for security Realms). Otherwise - server.xml/web.xml. In your case I suggest you to use web app embedded context.xml.

Upvotes: 16

shyam_prakash
shyam_prakash

Reputation: 89

This entry can go in server.xml under or in individual context files. Context xml files can be specific to each application deployment, whereas server.xml becomes global.

Application specific context files are usually located in catalina\localhost folder.

Upvotes: 2

hcg
hcg

Reputation: 652

The server.xml is used for server and context.xml is for application that runs on that server. There may be several context.xml files (per application) on a server but only one server.xml.

Upvotes: 16

Related Questions