我的maven配置
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.8.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
<scope>compile</scope>
</dependency>
然后我在main函数中调用一切正常
public class Test {
private static final Logger LOGGER = LogManager.getLogger(Test.class);
public static void main(String[] args) {
LOGGER.error("cuo wu");
}
}
但是在servlet中使用就会报错
@WebServlet(urlPatterns = "/index")
public class Test extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final Logger LOGGER = LogManager.getLogger();
LOGGER.error("aefaefe");
resp.getWriter().write("hi");
}
}
错误信息是
java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
希望有经验的大佬帮帮忙
You can check whether the corresponding class file exists in the project's release directory