3

I am using Log4j in a java web app.

Now, when I run a servlet of that web app, this is the error message that I get--

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.NoClassDefFoundError: org/apache/log4j/Logger
com.test.ConfigHelper.<clinit>(ConfigHelper.java:45)
com.test.runsinglecrawljob.doGet(runsinglecrawljob.java:126)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause


java.lang.ClassNotFoundException: org.apache.log4j.Logger
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
com.test.ConfigHelper.<clinit>(ConfigHelper.java:45)
com.test.runsinglecrawljob.doGet(runsinglecrawljob.java:126)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Now the line of code in ConfigHelper.java (line 45) is given below---

protected static final Logger log = Logger.getLogger(ConfigHelper.class);

I checked Java Build Path-- the JAR file for log4j has been added to build path.

What am I doing wrong here? How do I make log4j work without any problems?

1 Answer 1

11

I checked Java Build Path-- the JAR file for log4j has been added to build path.

Being part of the build path isn't enough - you need to make sure it's available at execution time, for example by putting it in the WEB-INF/lib directory in your web application, or potentially in the library path of your servlet container.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.