web-dev-qa-db-de.com

Die Log4j2-Konfiguration wurde nicht gefunden, wenn eine eigenständige Anwendung ausgeführt wird, die mit dem Farb-Plugin erstellt wurde

Ich habe eine Anwendung, die läuft, wenn ich aus Maven log4j2 laufe:

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

wenn ich jar jedoch als eigenständige Anwendung ausführen, wird ein Fehler angezeigt:

Java -jar

log:

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.

Ich verstehe diesen Fehler nicht. Es zeigt, dass die Konfigurationsdatei log4j2 nicht gefunden wird, aber sie beschwert sich auch über ein Format, das sich wahrscheinlich in der Konfigurationsdatei befindet

Meine Konfiguration ist:

<?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>

und es befindet sich im Stammverzeichnis der JAR-Datei.

AKTUALISIEREN

jar wird von maven shade plugin erstellt:

        <groupId>org.Apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>

es enthält also alle notwendigen Bibliotheken (ca. 23 MB), und wenn ich diese Dose starte, muss ich nur Argumente angeben 

21
hudi

ok Ich habe dieses Problem über dieses Problem gefunden.

Kurz gesagt, das Problem tritt auf, wenn Anwendungsklassen mithilfe von Maven Shade Plugin in mehr als Glas verpackt werden. Während für log4j2 Version 2.8.1 das Update noch aussteht, wird empfohlen, maven pom.xml mit zusätzlichen Konfigurationseinstellungen für das Schatten-Plugin wie folgt zu aktualisieren: 

    <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>
17
hudi

Das vollständige Beispiel für pom.file finden Sie hier.

Zusätzlich zur Antwort von @hudi, Müssen wir Abhängigkeiten im Plugin für die Umwandlung hinzufügen.

<build>
    <sourceDirectory>src/main/Java</sourceDirectory>
    <resources>
        <resource>
            <directory>src/main/resources</directory>               
        </resource>
    </resources>
    <plugins>
    <plugin>
    <groupId>org.Apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.Apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <manifestEntries>
                    <Main-Class>com.auto.facade.RunMain</Main-Class>
                    <Build-Number>123</Build-Number>
                </manifestEntries>
            </transformer>
            <transformer implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer" />                
          </transformers>
          <filters>
            <filter>
                <artifact>*:*</artifact>
                <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                </excludes>
            </filter>
         </filters>
        </configuration>
      </execution>
    </executions>
    <dependencies>
                <dependency>
                    <groupId>com.github.edwgiz</groupId>
                    <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
                    <version>2.6.1</version>
                </dependency>
            </dependencies>
  </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
</build>
6
Tony
<plugin>
            <groupId>org.Apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <finalName>project-name-product-1.0.0-SNAPSHOT</finalName>
                        <transformers>
                            <transformer
                                    implementation="org.Apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>your.main.classname</mainClass>
                            </transformer>
                            <transformer implementation="org.Apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer implementation="org.Apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer implementation="org.Apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.tooling</resource>
                            </transformer>
                            <transformer
                                    implementation="org.Apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer"/>
                            <transformer
                                    implementation="org.Apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            <transformer implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer" />

                        </transformers>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.github.edwgiz</groupId>
                    <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
                    <version>2.6.1</version>
                </dependency>
            </dependencies>
        </plugin>
0
user2576114