• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting exception while instantiating servlet class

 
indu yeturu
Ranch Hand
Posts: 123
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
indu yeturu
Ranch Hand
Posts: 123
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, Martijn I added all the required jars in classpath...
still getting the same exception..
thanks
indu
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks like a web application. How did you add that jar to the classpath?
 
indu yeturu
Ranch Hand
Posts: 123
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for all who responded to me..
It has solved...
indu
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 123
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic