问题描述
注意:已编辑(文件名/包名更改) $>> java -jar build \lib\somePackageName.jar
log4j:WARN记录器(xxx.xxx.xxxx.xxxxx)找不到appender。
log4j:WARN请正确初始化log4j系统。
log4j:WARN请参阅http://logging.apache.org/log4j/1.2/faq.html#noconfig了解更多信息。
已验证的jar包含log4j2.xml:
$>> jar tf build \libs\somePackageName.jar | ack -ilog4j2
META-INF / org / apache / logging / log4j / core / config / plugins / Log4j2Plugins.dat
META-INF / org / apache / logging / log4j / core / config /plugins/Log4j2Plugins.dat
log4j2.xml
使用依赖性构建Jar的Gradle任务:
sourceSets {
main {
资源{
srcDirs = ['src / resources' ]
}
}
}
任务someFatJar(类型: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()?它:zipTree(it)}}
with jar
}
项目树:
src\main\java\someJavaFile.java
src\resources\log4j2.xml
(以防万一,我试着移动主目录下的resources目录)
帮助!
使用slf4j + log4j2依赖关系是个问题!替换如下的依赖关系(不要使用slf4j-log4j-impl),使用log4j2(log4j-slf4j-impl)中的一次:
dependencies {
compile'org.slf4j:slf4j-api:1.7.25'
compile'org.apache.logging.log4j:log4j-api:2.8.2'
编译'org.apache.logging.log4j:log4j-core:2.8.2'
compile'org.apache.logging.log4j:log4j-slf4j-impl:2.8.2'
}
Note: edited (filenames/packagenames changed)
$>> java -jar build\lib\somePackageName.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.
validated jar has log4j2.xml:
$>> jar tf build\libs\somePackageName.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 task to build Jar with dependencies:
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
}
Project Tree:src\main\java\someJavaFile.javasrc\resources\log4j2.xml
(just in case, i tried moving "resources" directory under main)
Help!
Solution:using slf4j + log4j2 dependencies was the issue! replaced the dependencies as below (do not use slf4j-log4j-impl), use the 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'
}
这篇关于log4j2错误:通过Gradle生成运行jar - log4j:WARN没有找到记录器的appender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!