I have a Class named Mo.
Mo has a static function as below:
public static void logsomething(String s)
The body of the logsomething use the log4j(jar). That’s not a problem.
I also have a Main function:
public static void main(String[] args) {
// TODO Auto-generated method stub
Mo.logsomething("sth");
}
I called the Mo.logsomething() in main. It’s OK. No error.
But I call this Mo.logsomething(“sth”) in Servlet doGet:
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Mo.logsomething("sss");
response.getWriter().println("<h1>hello</h1>");
}
Get an exception:
java.lang.NoClassDefFoundError: org/apache/log4j/Layout
So it’s weird. I try to debug to see what happend.
When the debug cursor is on the line:Mo.logsomething(“sss”);
I press F5 to step in the code.
But I get the error:source not found.
What’s wrong with me?
You’re not writing what application server you use. But your error is likely to be an classpath error.
The problem is that your application server could not find the
Log4Jlibrary.Usually this problem can be solved by putting the
Log4Jjar file into theWEB-INF/lib/directory of your web application and deploy that application again.