注意:已编辑(文件名/包名已更改(
$>> java -jar buildlibsomePackageName.jar
log4j:WARN No appenders could be found for logger (xxx.xxx.xxxx.xxxxx).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
已验证的 JAR 具有 Log4J2.xml:
$>> jar tf buildlibssomePackageName.jar | ack -i "log4j2"
META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
log4j2.xml
Gradle 任务来构建带有依赖项的 Jar:
sourceSets {
main {
resources {
srcDirs = ['src/resources']
}
}
}
task someFatJar(type: Jar) {
manifest {
attributes (
'Implementation-Title': 'xxxxx-xxxxxxxx',
'Implementation-Version': 0.x,
'Main-Class': 'xxx.xxxxx.xxxxx.xxxxxxxxxxxx'
)
}
baseName = 'someJarName'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
项目树:src\main\java\someJavaFile.javasrc\resources\log4j2.xml
(以防万一,我尝试在main下移动"资源"目录(
帮助!
解决方案:使用 SLF4j + log4J2 依赖项是问题所在!替换了如下依赖项(不要使用 SLF4J-log4J-IMPL(,使用 Once Available from log4J2 (log4j-slf4j-impl(:
dependencies {
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'org.apache.logging.log4j:log4j-api:2.8.2'
compile 'org.apache.logging.log4j:log4j-core:2.8.2'
compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.8.2'
}
log4j:WARN
的错误消息是由旧的log4j 1.2实现生成的。您需要删除该依赖项并将其替换为log4j-1.2-api
适配器。这样,您就可以使用 Log4j2 作为编码到 log4j 1.2 API 的应用程序的日志记录后端。