为什么Log4j认为我的项目在Servlet环境中运行 [英] Why Log4j thinks my project run in Servlet Environment

查看:29
本文介绍了为什么Log4j认为我的项目在Servlet环境中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Java项目(Maven).这将构建一个jar,然后在其上执行main方法.但是,当我在项目上运行 mvn clean test 时,我从log4j看到一条日志行,

I have a simple java project (maven). Which builds a jar and we execute the main method on it. But when I run mvn clean test on the project I get a log line from log4j saying

INFO Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.

log4j2.xml 文件位于 src/main/resources/log4j2.xml 中.

有什么想法吗?

推荐答案

如果您的类路径中有 servlet-api Jar,则Log4j会认为您正在Servlet容器中运行.具体来说,它将查找 javax.servlet.ServletContext 的存在.如果您的应用程序不在Servlet容器中运行,那么您实际上就不需要该Jar.

If you have the servlet-api Jar in your classpath, Log4j is going to think you are running in a Servlet container. Specifically, it looks for the presence of javax.servlet.ServletContext. If your application is not running in a Servlet container, then you really shouldn't need that Jar.

这篇关于为什么Log4j认为我的项目在Servlet环境中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆