• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to avoid conflicts with Tomcat "lib" JARs

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)?
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Douglas Rapp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

geronimo-j2ee-management_1.0_spec-1.0.jar
geronimo-jms_1.1_spec-1.1.1.jar
commons-logging-1.1.1.jar

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.
 
Douglas Rapp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic