Thanks Jake I have commented some of your suggestions below.
Fredag 26 oktober 2007 06:36 skrev Jacob Kjome: > Jon Friis wrote: > > Hello > > > > I have a problem with log4j and commons-logging which i really hope > > anybody can help me with. > > > > Setup: > > Windows 2000, Apache Tomcat 6.0, JRE 1.6.0_02, log4j-1.2.15, > > commons-logging annd i am using eclipse 3.3.0 > > > > Since i have multiple Web services on the same Tomcat server i have been > > putting log4j.jar in WEB-INF/lib and log4j.properties in WEB-INF/classes. > > Note that this presumes child-first classloading, and that may not be > the case if you are running it from Eclipse. If you run Tomcat > Standalone, you will have child-first for sure. If you don't have > log4j.jar anywhere in a parent classloader, this is less of an issue, > but it still may not find your log4j.properties file if one exists in a > parent classloader without using child-first classloading. Even in the > case where you have child-first, but have log4j.xml in a parent > classloader, since log4j.xml is used in preference to log4j.properties, > log4j.xml will get used instead. Sorry to get a little off track. More > below... > > > My problem is some kind of class-loading problem where log4j and > > commons-logging won't find each other. > > > > 2 scenarios: > > > > 1) commons-logging.jar and log4j.jar are both put in WEB-INF/lib for my > > webapp. > > If, indeed, parent-first, rather than child-first, classloading is being > done, then this may not work if commons-logging exists in a parent > classloader. It will not see log4j.jar in a child classloader. > > > 2) commons-logging.jar is put in tomcat 6.0/lib (Common classloader > > according to tomcat 6.0 doc) and log4j.jar in WEB-INF/lib. > > Can you think of a way where commons-logging would be able to find > log4j.jar in this scenario? Classloaders look up, not down. If you put > log4j.jar in WEB-INF/lib and have libraries that depend on > commons-logging, then you must also put commons-logging.jar alongside > log4j.jar. Of course, you already tried that above. Hmmm.... I think i came to same conclusion my self, but when your desperate you'll try anything. > > > The stacktraces of both scenarios are given below. > > > > Question is: Why can't they see each other and how can i solve the > > problem ? > > > > Can it really be so that i have to wrap the log4j class (as describe in > > the log4j book) and can someone explain why and will it help ? > > > > Any feed back or solution hints are really appreciated :-) > > Try this. Put log4j.jar and commons-logging.jar (make sure it's not > commons-logging-api.jar) in Tomcat's "lib" directory. For per-app > logging, you'll also need either a repository selector (search the list > for info) or child-first classloading, plus log4j.jar and > commons-logging.jar in WEB-INF/lib (in addition to having them in > Tomcat's "lib" directory). So my conclusion is that when i run tomcat standalone on our test server everything works perfect as describe in 1) But in my development environment eclipse is changing the class-loader strategy or what ? (looks like it forces tomcat to do parent-first classloading instead of child first). Isn't this a bug in Eclispe ? i dont feel very happy about my develpoment tomcat isn't working in the same way as my test & production server. Should this be bugged to eclipse ? Thanks again Jake for your good suggestions and most of all for explaining to me why my setup didn't work. Now i understand the problem and have solved the problem more pragmatic. Since my test & production server is using child-first classloading i will stick to this. I my develoment i have the possibility to put all my JAR's in common lib - and this solves the problem in development. And after deploying my WAR file on test server i run a script to distributed my JAR dependecies right on the server. So now everything works as it should in test & prodcution, and i development the setup is a bit changed. Thx Jon Friis -- Jon Friis IT-Consultant & Owner Gavia Technologies ApS Omøgade 8, 2. sal 2100 Kbh. Ø M: +45 23820053 E: [EMAIL PROTECTED] W: www.gavia.dk Join my network at http://www.linkedin.com/in/jonfriis --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
