jakarta ee - Eclipse debug (use F5) in servlet and in Main a



我有一个名为Mo的类。Mo 具有如下静态函数:

public static void logsomething(String s) 

logsomething 的主体使用 log4j(jar)。这不是问题。

我还有一个 Main 函数:

public static void main(String[] args) {
        // TODO Auto-generated method stub
            Mo.logsomething("sth");
    }

我主要调用 Mo.logsomething()。没关系,没有错误。

但我在 Servlet doGet 中称之为 Mo.logsomething("sth"):

protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
            Mo.logsomething("sss");
        response.getWriter().println("<h1>hello</h1>");
    }

获取异常:java.lang.NoClassDefFoundError: org/apache/log4j/Layout

所以这很奇怪。我尝试调试以查看发生了什么。当调试光标位于行上时:Mo.logsomething("sss");我按 F5 单步执行代码。但是我得到错误:找不到源。

我怎么了?

你不是在编写你使用的应用程序服务器。但是您的错误很可能是类路径错误。

问题是您的应用程序服务器找不到Log4J库。

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

最新更新