Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tomcat and class loading...?

Status
Not open for further replies.

aRaindogToo

Programmer
Dec 28, 2004
5
SE
Hi!

Anybody has some info about Tomcat and class loading? I have a servlet that uses the logging functionality i java.util.logggin package, but also have a class extending the SimpleFormatter class. To change between these formatters, the "java.util.logging.FileHandler.formatter" key is used. The only way I've found to get java runtime to find my class, is to set the "java.endorsed.dirs" to CATALINA_BASE/common/endorsed (which contains the jar with my class) when I run the tomcat start script (CATALINA_HOME is not the same as CATALINA_BASE).

Is there any other way? Ok, it works, but it doesn't seem like it's the right way to go.

Any info would be greatly appreciated!

BR,
jonas
 
Just put the jar file in TOMCAT_HOME/common/lib and the container ClassLoader will pick it up.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hi again!

Ok, thanks, but just to be sure that I know what you mean: what is TOMCAT_HOME referring to (CATALINA_HOME?)? I mean, what I want to do is to separate my web app (stored in CATALINA_BASE) from the tomcat installation (CATALINA_HOME), completely. I do not want to add something to an already installed tomcat installation, but keep all my web app related files separately, and just call the tomcat start script.

Possible?

Thanks again!

BR,
jonas
 
If it is a jar that all webapps will potentially use, then put it in TOMCAT_HOME/common/lib.
If it is a jar that only your webapp will use, then put it in WEBAPP_HOME/WEB-INF/lib.

BTW, TOMCAT_HOME = CATALINA_HOME.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hi again...again!

Then I'm probably using the java logging functionality wrong. I start tomcat in the CATALINA_BASE dir, running the CATALINA_HOME/bin/startup script. The logging properties file (which has "java.util.logging.FileHandler.formatter" set to my own formatter) used by my application loggers is located in CATALINA_BASE/conf/.

The ONLY way I can get java runtime to use my formatter is to put the jar file in:
1. CATALINA_HOME/common/endorsed
2. JAVA_HOME/jre/lib/ext, or
3. CATALINA_BASE/common/endorsed, and set the java.endorsed.dirs parameter to point to this directory while starting tomcat.

Putting the jar/class file into CATALINA_HOME/common/lib, CATALINA_HOME/common/classes, CATALINA_BASE/webapps/aWepapp/WEB-INF/lib, CATALINA_BASE/shared etc, will only result in either a NoClassDefFoundError or the default java formatter (XML) being used.

Perhaps there is no way around this, or, as I said, perhaps I should use the logging functionality differently. I really don't want to add something to an already installed tomcat, and thought I could keep my own classes in a separate location. Which do work if I set the java.endorsed.dirs parameter, but...

Well, anyway, thanks for the help!

BR,
jonas
 
I guess its possible that there is some kind of class conflict between your logging util and Tomcat's own one - and by adding it to the endorsed list, Tomcat is not loading its own version - but thats a wild guess.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top