Tomcat JNDI Shares

Im running a couple of servlet applications in Tomcat (5.5). All servlets use the factory share, which is shared with JNDI. At the moment, I can get everything by including the factory resource as the GlobalNamingResource file in the /conf/server.xml file, and then when each servlet of the META-INF / context.xml file includes the ResourceLink in the resource. The following are snippets of XML files. NOTE: I am not familiar with tomcat, so I am not saying that this is a good configuration.

However, now I want these servlets to be able to be installed on multiple tomcat instances automatically using RPM. RPM will first copy WARs to the webapps directory and banks for the factory to the common / lib directory (which is good). But you also need to make sure that the factory resource is included as a resource for all servlets.

What is the best way to add a resource globally? I'm not too keen on writing a script that goes into server.xml and adds to the resource this way. Is there a way to add multiple server.xml files so that I can write a new server-app.xml file and it will concatenate my settings with server.xml? Or is it even better to add this JNDI resource to all servlets without using server.xml?

ps Restarting the server will not be a problem, so I do not mind if the changes are not received 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 of the 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> 
+6
java resources tomcat jndi
source share
4 answers

Starting with Tomcat 4, the recommendation was to not put any JNDI information in the server.xml file. Check out Tomcat 5.5 Documentation :

For Tomcat 5, unlike Tomcat 4.x, it is NOT recommended to place elements directly in the server.xml file. This is because it makes the context configuration change more invasive, since the main conf / server.xml file cannot be reloaded without restarting Tomcat.

I know that you claim that you do not care about this, but believe me, your deployment team does, and the support team will thank you later. Even if it means that you end up thanking yourself.

If you want the JNDI parameter to be common to all web servers on the server, you must put it in the $ CATALINA_HOME / conf / context.xml file. In all likelihood, there will already be an existing context.xml file in this place, but you should be able to write a simple application to add resource nodes through your favorite language and any DOM linker comes with it. Or, if you want to stick to the command line, check out this article , which contains several XML shell scripts to help you.

Good luck

+1
source share

in fact, we have a case where we cannot put (for example) the jdbc configuration in the war: the client will never tell us the username and password for the production server, so we had to determine the data source in the global server configuration and put the link in context .xml applications, e.g. op. The global configuration can be placed either in server.xml or in tomcat context.xml (it seems that the second approach is preferable on the Windows platform).

+1
source share

This does not directly answer your question, but instead, you decided to put all your configuration in your context.xml file, and not in server.xml? This makes your web application more self-contained, which is important for your deployment requirements.

I would say that it might be worth considering any refactoring necessary to ensure that your applications can be fully self-contained if this is not possible at the moment.

Work on projects in which I deployed / common / lib JAR and shared resources, and was bitten by them in a confusing and subtle way (I eventually found out that it was always my own mistake, but not blaming Tomcat here), now I take a completely protective approach to my webapps: keep them completely independent.

But, of course, I do not fully know your circumstances, just some suggestions.

0
source share

This is what I would do, I use Maven 3, I would put server.xml in my resources directory or some other directory where I can run filter , and dynamically replace and generate the corresponding server.xml when I make the package . Then you can use the maven-rpm plugin and automate the generation of revolutions.

0
source share

All Articles