I am running Tomcat 5.5.16, and I have a couple of DataSources set up in the
GobalNamingResources section of my server.xml. Now, I preferably want to be
able to access these resources without having to set up a separate <Context>
section for each application, so I can deploy new applications that access
these resources without having to modify my server configuration.
Currently, the only way I am able to access the DataSources is to set things
up like this:
<GlobalNamingResources>
<Environment
name="productionMode"
type="java.lang.String"
value="TEST"/>
<Resource
auth="Container"
driverClassName="com.ibm.as400.access.AS400JDBCDriver"
name="jdbc/xxx1"
password="xxx"
type="javax.sql.DataSource"
url="jdbc:as400://abc.def.com"
username="xxx"/>
<Resource
auth="Container"
driverClassName="com.ibm.as400.access.AS400JDBCDriver"
name="jdbc/xxx2" password="xxx"
type="javax.sql.DataSource"
url="jdbc:as400://ghi.jkl.com" username="xxx"/>
<Resource
auth="Container"
driverClassName="com.ibm.as400.access.AS400JDBCDriver"
name="jdbc/xxx3"
password="xxx"
type="javax.sql.DataSource"
url="jdbc:as400://mno.pqr.com"
username="xxx"/>
</GlobalNamingResources>
......
<Engine
defaultHost="localhost"
name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
<Host
appBase="webapps"
name="localhost"
autoDeploy="true"
liveDeploy="true"
unpackWARs="true">
<Context docBase="myApp" path="/myApp" reloadable="true">
<ResourceLink global="productionMode" name="productionMode" type="
java.lang.String"/>
<ResourceLink global="jdbc/xxx1" name="jdbc/xxx1" type="
javax.sql.DataSource" />
<ResourceLink global="jdbc/xxx2" name="jdbc/xxx2" type="
javax.sql.DataSource" />
<ResourceLink global="jdbc/xxx3" name="jdbc/xxx3" type="
javax.sql.DataSource" />
</Context>
</Host>
</Engine>
My question is, can I create the links to the global resources in my web.xml?
Or are my only options to do either:
1) Create a context for each new application with the resource links
2) Create the resources in the web.xml on a per-application basis.
Option 1) is inconvenient but doable. Option 2) isn't really an option,
because at the very least, I need to set some server-level environment
variables that the applications read.
So, is there a way for me to get around having to create a <Context> for
each application I want to install? <DefaultContext> didn't work for me.
Thanks,
David Uctaa