This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Getting exception while instantiating servlet class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Getting exception while instantiating servlet class" Watch "Getting exception while instantiating servlet class" New topic
Author

Getting exception while instantiating servlet class

indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
Hi,

am new to log4j and try to use it in one starting Testing Servlet.
I created log4j.properties in WEB-INF/classes and placed the all the required jars correctly.

When I try to run my servlet with this code

private static Logger logger = Logger.getLogger(X.class);

am getting the exception --->>>
"javax.servlet.ServletException: Error instantiating servlet class X"

and rootcause --->>>>
"java.lang.NoClassDefFoundError: org/apache/log4j/Logger"

can you please help me how to resolve it??

thanks
indu


thanks,
indu
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Indu,

It's basically saying that it can't find the log4j classes on the CLASSPATH, do you have log4j-<version>.jar somewhere on the CLASSPATH?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
yes, Martijn I added all the required jars in classpath...
still getting the same exception..
thanks
indu
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9924
    
158

This looks like a web application. How did you add that jar to the classpath?


[My Blog] [JavaRanch Journal]
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
thanks for all who responded to me..
It has solved...
indu
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Indu,

Can you post here how you solved it? It will help others that have the same problem! Oh and well done!
indu yeturu
Ranch Hand

Joined: Aug 27, 2008
Posts: 123
Hi Martijn,

At first what your observation was correct. You advised me to check classpath properly. I added log4j(..).jar in project level WEB-INF/lib...
and thought it is enough. But after adding log4j(..).jar in commons/lib under the Tomcat-home ,then it started to find that jar. My first web application with log4j is working fine now.


thanks
indu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting exception while instantiating servlet class
 
Similar Threads
Log4j
log4j:ERROR setFile(null,true) call failed.
"NoClassDefFound Error" deploying EAR file
sevlet error : Error allocating a servlet instance
inject log4j logger