Common JNDI resources in Tomcat
- by Lehane
Hi,
I’m running a couple of servlet applications in Tomcat (5.5). All of the servlets use a common factory resource that is shared out using JNDI. At the moment, I can get everything working by including the factory resource as a GlobalNamingResource in the /conf/server.xml file, and then having each servlet’s META-INF/context.xml file include a ResourceLink to the resource. Snippets from the XML files are included below. NOTE: I’m not that familiar with tomcat, so I’m not saying that this is a good configuration!!!
However, I now want to be able install these servlets into multiple tomcat instances automatically using an RPM. The RPM will firstly copy the WARs to the webapps directory, and the jars for the factory into the common/lib directory (which is fine). But it will also need to make sure that the factory resource is included as a resource for all of the servlets.
What is the best way add the resource globally? I’m not too keen on writing a script that goes into the server.xml file and adds in the resource that way.
Is there any way for me to add in multiple server.xml files so that I can write a new server-app.xml file and it will concatenate my settings to server.xml? Or, better still to add this JNDI resource to all the servlets without using server.xml at all?
p.s. Restarting the server will not be an issue, so I don’t mind if the changes don’t get picked up automatically.
Thanks
Snippet from server.xml
<!-- Global JNDI resources -->
<GlobalNamingResources>
<Resource name="bean/MyFactory"
auth="Container"
type="com.somewhere.Connection"
factory="com.somewhere.MyFactory"/>
</GlobalNamingResources>
The entire servlet’s META-INF/context.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<ResourceLink global="bean/MyFactory"
name="bean/MyFactory"
type="com.somewhere.MyFactory"/>
</Context>