So to start off - this problem is still theoretical. I haven't gotten around to actually testing and debugging, etc. So I don't have any specific errors or complications to refer to yet... But here is the issue:
I have a web application that uses log4j, and as such, includes a log4j JAR file in its "WEB-INF/lib" folder.
I also have a JAR file that needs to be deployed in Tomcat's "lib" folder because I need to make a JNDI resource available to ALL web applications installed.
However, the code in that common JAR file depends on log4j as well, requiring me to also place a log4j JAR in Tomcat's "lib" folder.
So the question: how do I make sure that the two log4j libraries don't conflict? Both will be loaded with different class loaders, but both will technically be available to my web application. Is it best practice to just configure logging at the Tomcat level and not at the individual web application level (ie, should I remove logging implementation and configuration from my web application in favor of a global configuration)?
It is rarely a good idea to put sharable resources in the Tomcat library directory. Stuff like connection pools (database drivers) are OK, since they're part of the Tomcat server, but independent resources shouldn't be kept there unless there is no safer way to do it.
Tomcat itself uses JULI for logging, so even before you start thinking about conflicts between apps and the shared code, you need to consider that you have a conflict between the shared code and Tomcat.
If you could describe what this resource is, I could give better advice, however.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Nov 29, 2011
Good point. I didn't take into consideration conflicts with Tomcat itself.
For more information, the resource that I am talking about is an ActiveMQ library, activemq-core-5.3.0.jar (I will be looking in to a more up-to-date version in the near future, but the same issue exists). If I place this JAR into Tomcat's lib folder, it needs to be accompanied by at least some version of the following other JARs, or I get ClassNotFound errors:
Sorry, I misspoke in the original post. The logging provider in question is not log4j - it's Apache Commons Logging.
In any case, how can I be sure that this logging resource (not to mention any other resource that might be in there) won't conflict with Tomcat and my web application? Looking at newer versions of the activemq-core library reveals that if I up the version, I'll also need to add an slf4j-api in there.
Joined: Nov 29, 2011
By the way, the reason for all this is to provide pooled connections to my JMS broker available to all web applications via JNDI lookup.
If you are using Apache ActiveMQ, I would recommend that you get their special version of Tomcat that has ActiveMQ already bundled into it.
There are various sets of instructions for adding ActiveMQ to an existing Tomcat, but which set you need depends on many factors, including which Tomcat version and how you manage your pooling.
If the version of ActiveMQ you are attempting to integrate requires geronimo jars, I doubt very much it will work. Geronimo was a completely different webserver. As far as I can tell, it's also quite extinct these days, so support may not be easy to find.
I believe that the apache commons-logging package is a logging aggregator and rather than giving you logging conflicts, it should make ActiveMQ's logging more co-operative with Tomcat's logging.