注:編輯(文件名/ packagenames改變)log4j2錯誤:通過搖籃產生運行罐子 - 的log4j:警告沒有附加目的地可以發現記錄
$>> 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.
驗證罐子有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
搖籃任務與依賴關係構建的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 \主\ java的\ someJavaFile.java 的src \資源\ log4j2.xml
(以防萬一,我想下的主要動 「資源」 目錄)
幫助!