• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting exception while instantiating servlet class

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, Martijn I added all the required jars in classpath...
still getting the same exception..
thanks
indu
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for all who responded to me..
It has solved...
indu
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic