You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Craig Newlander <cn...@eqtc.com> on 2001/08/22 16:55:05 UTC

Log4j and servlets - Reflection Error

Strange error here.
In my Servlet class (foo) I defined a static field member as

private static Category log;

and in its Constructor is
log = Category.getRoot();
I can now log until the cows come home.

Now then, I have another class (foobar) which is instantiated via reflection
by foo from foo's service() method

foobar has a static field member as
private static Category log;
and in its Constructor is
log = Category.getInstance(  this.getClass().getName() );

and when foo tries to reflect foobar I recevied a
java.lang.reflect.InvocationTargetException: java.lang.NoClassDefFoundError:
org/apache/log4j/Category
foobar never gets instantiated foo keeps chugging along and logs without a
hitch?

if I remove the log = from foobars construtor foobar can be reflected just
fine.

Any ideas?





---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


RE: Log4j and servlets - Reflection Error

Posted by Craig Newlander <cn...@eqtc.com>.
Putting the log4j.jar file in the lib directory of WEB-INF/ works fine
for servlets (but the not the classes w/ lo4j referencesthat the servlet
refelcts

After putting the .jar file in the classpath everything works fine.

I guess that makes sense.


-----Original Message-----
From: Thomas Tuft Muller [mailto:ttm@online.no]
Sent: Thursday, August 23, 2001 1:39 AM
To: LOG4J Users Mailing List
Subject: RE: Log4j and servlets - Reflection Error


There's a few unintentional discrepencies in the various VMs with respect to
reflection. I've e.g. seen the InvocationTargetTxception if I reflect with
an anonymous class as opposed to an explicitly defined inner class.

BTW, unless Foo is a Singleton, the static log field will be assigned for
each invocation of the constructor. A side-effect (unless Foo is final) is
that you reassign it when a sub-class of foo is created as well (that is if
the constructor assigning 'log' is called by this sub-class constructor).
This is probably NOT your intention.

I use a similar technique, but I let the category reference be an instance
variable. More memory consumption, but less side-effect prone.

--

Thomas


| -----Original Message-----
| From: Craig Newlander [mailto:cnewlander@eqtc.com]
| Sent: 22 August 2001 15:55
| To: LOG4J Users Mailing List
| Subject: Log4j and servlets - Reflection Error
|
|
| Strange error here.
| In my Servlet class (foo) I defined a static field member as
|
| private static Category log;
|
| and in its Constructor is
| log = Category.getRoot();
| I can now log until the cows come home.
|
| Now then, I have another class (foobar) which is instantiated via
| reflection
| by foo from foo's service() method
|
| foobar has a static field member as
| private static Category log;
| and in its Constructor is
| log = Category.getInstance(  this.getClass().getName() );
|
| and when foo tries to reflect foobar I recevied a
| java.lang.reflect.InvocationTargetException:
| java.lang.NoClassDefFoundError:
| org/apache/log4j/Category
| foobar never gets instantiated foo keeps chugging along and logs without a
| hitch?
|
| if I remove the log = from foobars construtor foobar can be reflected just
| fine.
|
| Any ideas?
|
|
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: log4j-user-help@jakarta.apache.org
|
|



*************************************************************************
Copyright ERA Technology Ltd. 2001. (www.era.co.uk). All rights reserved.
Confidential. No liability whatsoever is accepted for any loss or damage
suffered as a result of accessing this message or any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


RE: Log4j and servlets - Reflection Error

Posted by Thomas Tuft Muller <tt...@online.no>.
There's a few unintentional discrepencies in the various VMs with respect to
reflection. I've e.g. seen the InvocationTargetTxception if I reflect with
an anonymous class as opposed to an explicitly defined inner class.

BTW, unless Foo is a Singleton, the static log field will be assigned for
each invocation of the constructor. A side-effect (unless Foo is final) is
that you reassign it when a sub-class of foo is created as well (that is if
the constructor assigning 'log' is called by this sub-class constructor).
This is probably NOT your intention.

I use a similar technique, but I let the category reference be an instance
variable. More memory consumption, but less side-effect prone.

--

Thomas


| -----Original Message-----
| From: Craig Newlander [mailto:cnewlander@eqtc.com]
| Sent: 22 August 2001 15:55
| To: LOG4J Users Mailing List
| Subject: Log4j and servlets - Reflection Error
|
|
| Strange error here.
| In my Servlet class (foo) I defined a static field member as
|
| private static Category log;
|
| and in its Constructor is
| log = Category.getRoot();
| I can now log until the cows come home.
|
| Now then, I have another class (foobar) which is instantiated via
| reflection
| by foo from foo's service() method
|
| foobar has a static field member as
| private static Category log;
| and in its Constructor is
| log = Category.getInstance(  this.getClass().getName() );
|
| and when foo tries to reflect foobar I recevied a
| java.lang.reflect.InvocationTargetException:
| java.lang.NoClassDefFoundError:
| org/apache/log4j/Category
| foobar never gets instantiated foo keeps chugging along and logs without a
| hitch?
|
| if I remove the log = from foobars construtor foobar can be reflected just
| fine.
|
| Any ideas?
|
|
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: log4j-user-help@jakarta.apache.org
|
|



*************************************************************************
Copyright ERA Technology Ltd. 2001. (www.era.co.uk). All rights reserved. 
Confidential. No liability whatsoever is accepted for any loss or damage 
suffered as a result of accessing this message or any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


RE: Log4j and servlets - Reflection Error UPDATE

Posted by Craig Newlander <cn...@eqtc.com>.
update:

If using plain vanilla servlets then putting the .jar file in the
WEB-INF/lib directory and doing nothing to the classpath log4j works just
fine.

It seems that if you use reflection to instantiate a class that is using
log4j then the appropriate loj4j .jar file needs to be in the classpath
otherwise the relected class will not be instantiated.

Craig

-----Original Message-----
From: Ceki Gülcü [mailto:cgu@qos.ch]
Sent: Wednesday, August 22, 2001 2:37 PM
To: LOG4J Users Mailing List
Subject: Re: Log4j and servlets - Reflection Error



Craig,

No idea at all. Sorry I can't help. Ceki

At 09:55 22.08.2001 -0500, Craig Newlander wrote:
>Strange error here.
>In my Servlet class (foo) I defined a static field member as
>
>private static Category log;
>
>and in its Constructor is
>log = Category.getRoot();
>I can now log until the cows come home.
>
>Now then, I have another class (foobar) which is instantiated via
reflection
>by foo from foo's service() method
>
>foobar has a static field member as
>private static Category log;
>and in its Constructor is
>log = Category.getInstance(  this.getClass().getName() );
>
>and when foo tries to reflect foobar I recevied a
>java.lang.reflect.InvocationTargetException:
java.lang.NoClassDefFoundError:
>org/apache/log4j/Category
>foobar never gets instantiated foo keeps chugging along and logs without a
>hitch?
>
>if I remove the log = from foobars construtor foobar can be reflected just
>fine.
>
>Any ideas?

--
Ceki Gülcü - http://qos.ch


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: Log4j and servlets - Reflection Error

Posted by Ceki Gülcü <cg...@qos.ch>.
Craig,

No idea at all. Sorry I can't help. Ceki

At 09:55 22.08.2001 -0500, Craig Newlander wrote:
>Strange error here.
>In my Servlet class (foo) I defined a static field member as
>
>private static Category log;
>
>and in its Constructor is
>log = Category.getRoot();
>I can now log until the cows come home.
>
>Now then, I have another class (foobar) which is instantiated via reflection
>by foo from foo's service() method
>
>foobar has a static field member as
>private static Category log;
>and in its Constructor is
>log = Category.getInstance(  this.getClass().getName() );
>
>and when foo tries to reflect foobar I recevied a
>java.lang.reflect.InvocationTargetException: java.lang.NoClassDefFoundError:
>org/apache/log4j/Category
>foobar never gets instantiated foo keeps chugging along and logs without a
>hitch?
>
>if I remove the log = from foobars construtor foobar can be reflected just
>fine.
>
>Any ideas?

--
Ceki Gülcü - http://qos.ch


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org