servlet和主应用程序中的Eclipse调试(使用F5)

servlet和主应用程序中的Eclipse调试(使用F5),eclipse,jakarta-ee,log4j,Eclipse,Jakarta Ee,Log4j,我有一个班叫莫。 Mo具有如下静态功能: public static void logsomething(String s) logsomething的主体使用log4j(jar)。这不是问题 我还有一个主要功能: public static void main(String[] args) { // TODO Auto-generated method stub Mo.logsomething("sth"); } 我在main中调用了Mo.

我有一个班叫莫。 Mo具有如下静态功能:

public static void logsomething(String s) 
logsomething的主体使用log4j(jar)。这不是问题

我还有一个主要功能:

public static void main(String[] args) {
        // TODO Auto-generated method stub
            Mo.logsomething("sth");
    }
我在main中调用了Mo.logsomething()。没关系。没有错误

但我在Servlet doGet中称之为Mo.logsomething(“某物”):

protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

            Mo.logsomething("sss");

        response.getWriter().println("<h1>hello</h1>");
    }
protectedvoiddoget(HttpServletRequest),
HttpServletResponse响应)引发ServletException,IOException{
Mo.logsomething(“sss”);
response.getWriter().println(“你好”);
}
获取异常: java.lang.NoClassDefFoundError:org/apache/log4j/Layout

所以这很奇怪。我试着调试看看发生了什么。 当调试光标位于以下行时:Mo.logsomething(“sss”); 我按F5键输入代码。 但我得到了一个错误:找不到源


我怎么了?

您没有编写您使用的应用程序服务器。但是您的错误可能是类路径错误

问题是应用程序服务器找不到
Log4J


通常,可以通过将
Log4J
jar文件放入WEB应用程序的
WEB-INF/lib/
目录并再次部署该应用程序来解决此问题。

我将jar文件复制到WEB-INF/lib/。但没有效果。有什么想法吗?你又部署了吗?您使用什么服务器?这是类路径错误,我将jar路径添加到运行配置->类路径。它起作用了。