为什么 Log4j 在 Servlet 环境中认为我的项目 运行
Why Log4j thinks my project run in Servlet Environment
我有一个简单的 java 项目 (maven)。它构建了一个 jar,我们在其上执行 main 方法。但是当我在项目上 运行 mvn clean test
时,我从 log4j 得到一条日志行说
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。
同样,如果您说加载它作为 JUnit 测试的一部分并希望消除错误,那么您始终可以像这样包含文件:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.6.2</version>
<scope>test</scope>
</dependency>
请注意范围已设置为测试,因此该文件将不会包含在任何构建工件中。
另请注意,此 "error" 实际上只是设置为 "info" 级别,因此 log4j 将继续提供非 Web 支持。
我在使用 depedency 时遇到了同样的问题:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>connect-json</artifactId>
<version>2.0.1</version>
</dependency>
当我还包括依赖项时我可以解决它:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.0.0</version>
</dependency>
到 pom.xml 文件。
我在这里没有太多的澄清,但这就是我在 Kafka 客户端领域工作时 运行 所做的。希望对某人有所帮助。
我有一个简单的 java 项目 (maven)。它构建了一个 jar,我们在其上执行 main 方法。但是当我在项目上 运行 mvn clean test
时,我从 log4j 得到一条日志行说
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。
同样,如果您说加载它作为 JUnit 测试的一部分并希望消除错误,那么您始终可以像这样包含文件:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.6.2</version>
<scope>test</scope>
</dependency>
请注意范围已设置为测试,因此该文件将不会包含在任何构建工件中。
另请注意,此 "error" 实际上只是设置为 "info" 级别,因此 log4j 将继续提供非 Web 支持。
我在使用 depedency 时遇到了同样的问题:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>connect-json</artifactId>
<version>2.0.1</version>
</dependency>
当我还包括依赖项时我可以解决它:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.0.0</version>
</dependency>
到 pom.xml 文件。 我在这里没有太多的澄清,但这就是我在 Kafka 客户端领域工作时 运行 所做的。希望对某人有所帮助。