Classloader and log4j dilemma

  • Thread starter news-server.nc.rr.com
  • Start date
N

news-server.nc.rr.com

Hi,

I am attempting to use log4j in a certain environment. That environment is
Rational Functional Tester (a java based GUI Automation tool).

Here is the problem, as far as I can narrow it down. There are two sets of
classes involved. RFT's library classes (in jar files), my own set of
classes for the automation (in a directory structure).

When I run the application, I unfortunately cannot add my own classes to the
classpath. RFT does not allow this (it has a gui that lauches the playback
and the command line it uses is not configurable). The way RFT works, is
that my classes get loaded by a special RFT classloader, not the application
classloader.

The problem is I have log4j Appender classes, that I wrote. But log4j
cannot load them because it uses the application class loader, and they are
not on the classpath.

I tried writing my own classloader, but that doesn't help because the log4j
classloader is the parent of mine and will not delegate to a child.

I am new at classloaders. Essentially what I want is to make my class
available to a parent classloader. Any ideas how to accomplish this? Or am
I hosed because of the inability to change the classpath? Should I begin
looking at ways to hack the classpath (which would be very inconvenient to
repeatedly re-jar as I develop)

Excuse my newness on classloading.
 
B

Babu Kalakrishnan

news-server.nc.rr.com said:
I am attempting to use log4j in a certain environment. That environment is
Rational Functional Tester (a java based GUI Automation tool).

Here is the problem, as far as I can narrow it down. There are two sets of
classes involved. RFT's library classes (in jar files), my own set of
classes for the automation (in a directory structure).

When I run the application, I unfortunately cannot add my own classes to the
classpath. RFT does not allow this (it has a gui that lauches the playback
and the command line it uses is not configurable). The way RFT works, is
that my classes get loaded by a special RFT classloader, not the application
classloader.

The problem is I have log4j Appender classes, that I wrote. But log4j
cannot load them because it uses the application class loader, and they are
not on the classpath.

I haven't used the RFT environment - but have you tried adding the log4j
jar file and your custom appender classes to your classpath ? This way
your application shoould have its own private log4j setup - no way
connected to that of RFT (since they're loaded through different
classloaders) which you should be able to initialize independently.

The way most classloaders work is to first try to load a clas using the
application classloader, and would delegate to the parent classloader
only if the app classloader cannot find a class. If that's the way the
RFT classloader works as well, I think you should end up with a copy of
log4j that works with your private log4j jar file, log4j.properties and
and your custom setup.

In short don't try to use the log4j that your host environment uses.

BK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top