简体   繁体   中英

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 ?

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.

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 (eg like it is for security Realms). Otherwise - server.xml/web.xml. In your case I suggest you to use web app embedded context.xml.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM