2016-01-22 3 views
11

У меня есть приложение, которое, когда я бегу от мавена log4j2 это работает:конфигурации Log4j2 не найден при запуске отдельного приложения строили с помощью тени плагин

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

, но когда я запускаю баночку как отдельное приложение, то он показывает ошибку:

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.

UPDATE

банка создается Maven тени плагин:

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

поэтому содержит все необходимые библиотеки (около 23 МБ), и когда я запускаю эту баночку мне просто нужно указать аргументы

+0

Можете ли вы дали некоторую информацию о том, как вы строите свой файл банку - это толстый сосуд, или, если нет, то как вы поставить путь к классам при выполнении его? – sfThomas

+0

Я столкнулся с той же проблемой при создании толстой банки, используя «maven-assembly-plugin», вы можете что-то предложить? –

ответ

8

ok Я нашел это issue об этой проблеме.

Короче говоря, проблема возникает, когда классы приложений упакованы в uber jar с использованием плагина maven shade. Хотя для log4j2 версии 2.8.1 исправление еще не принято, предложенное временное решение обновить Maven pom.xml с дополнительными параметрами конфигурации для тени плагина следующим образом:

<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> 
+0

Добавить это в какой файл? –

+1

to pom.xml, где у вас есть теневой плагин – hudi

+0

@hudi Как насчет использования муравьев? – Sohaib

4

Пожалуйста, обратитесь это за полный пример pom.file.

В дополнение к ответу @hudi, нам нужно добавить зависимости внутри плагина для преобразования.

<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> 
0
<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> 
+3

Привет, Спасибо за ответ. Хотя это может быть более полезно, если вы объясните, что он делает, как он решает проблему OP. – SCB

 Смежные вопросы

  • Нет связанных вопросов^_^