运行由Shade插件构建的独立应用程序时找不到Log4j2配置

我有从maven log4j2运行时可以运行的应用程序:

mvn exec:java -Dexec.args=...

但是当我将jar作为独立应用程序运行时,它显示错误:

java -jar

日志:

ERROR StatusLogger Unrecognized format specifier [d]

ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [thread]

ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [level]

ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [logger]

ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [msg]

ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [n]

ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

ERROR StatusLogger Unrecognized format specifier [d]

ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [thread]

ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [level]

ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [logger]

ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [msg]

ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.

ERROR StatusLogger Unrecognized format specifier [n]

ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.

我不明白这个错误。它显示未找到log4j2配置文件,但还抱怨配置文件中可能存在某种格式

我的配置是:

<?xml version="1.0" encoding="UTF-8"?>

<Configuration status="off">

<Appenders>

<Console name="console" target="SYSTEM_OUT">

<PatternLayout pattern="%d [%t] %-5p - %-26.26c{1} - %m\n" />

</Console>

</Appenders>

<Loggers>

<Root level="info">

<AppenderRef ref="console" />

</Root>

<Logger name="my.package" level="DEBUG" />

</Loggers>

</Configuration>

它位于jar文件的根目录中。

更新

jar由maven shade插件创建:

        <groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-shade-plugin</artifactId>

因此它包含所有必需的库(大约23 MB),当我运行这个jar时,我只需要指定参数

回答:

好吧,我发现这个问题,这个问题。

简而言之,当使用maven shade plugin将应用程序类打包在uber

jar中时,就会出现问题。虽然该log4j2版本2.8.1的修复程序仍在进行中,但建议的解决方法是pom.xml使用阴影插件的额外配置设置来更新Maven

,如下所示:

    <project xmlns="http://maven.apache.org/POM/4.0.0"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

. . . . .

<build>

. . . . .

<plugins>

. . . . .

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-shade-plugin</artifactId>

<version>2.4.1</version>

<configuration>

<filters>

<filter>

<artifact>*:*</artifact>

<excludes>

<exclude>META-INF/*.SF</exclude>

<exclude>META-INF/*.DSA</exclude>

<exclude>META-INF/*.RSA</exclude>

</excludes>

</filter>

</filters>

<transformers>

<transformer

implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer"/>

</transformers>

</configuration>

<executions>

<execution>

<phase>package</phase>

<goals>

<goal>shade</goal>

</goals>

</execution>

</executions>

<dependencies>

<dependency>

<groupId>com.github.edwgiz</groupId>

<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>

<version>2.1</version>

</dependency>

</dependencies>

</plugin>

. . . . .

</plugins>

. . . . .

</build>

. . . . .

<pluginRepositories>

<pluginRepository>

<id>oss.sonatype.org</id>

<name>OSS Sonatype Staging</name>

<url>https://oss.sonatype.org/content/groups/staging</url>

</pluginRepository>

</pluginRepositories>

. . . . .

</project>

以上是 运行由Shade插件构建的独立应用程序时找不到Log4j2配置 的全部内容, 来源链接: utcz.com/qa/401991.html

回到顶部