简体   繁体   English

Runnable Jar(JavaFx)使用spring boot maven插件作为构建器找不到log4j2.xml

[英]Runnable Jar (JavaFx) cannot find log4j2.xml using spring boot maven plugin as builder

I'm in a bit of a pickle. 我有点腌渍。

I have a master branch in git (Cant share sorry) that when built using the spring boot maven plugin, it works perfectly and nothing is wrong with it. 我在git中有一个主分支(Cant分享对不起),当使用spring boot maven插件构建时,它完美运行并且没有任何问题。 Now i do some work to a branch and add stuff to it (only added 2 dependencies), everything works but the logging. 现在我做了一些工作到分支并添加东西(只添加了2个依赖项),一切正常但日志记录。 It couldn't find my log4j2.xml configuration file and cannot produce a log file. 它找不到我的log4j2.xml配置文件,无法生成日志文件。

To my understanding (Please correct me if i'm wrong. I'm still trying to learn how to build runnable jars properly), when you build via maven spring plugin, it will just put all the required dependencies and classes (except for resources) in the executable jar file. 据我所知(如果我错了,请纠正我。我还在努力学习如何正确构建可运行的jar),当你通过maven spring插件构建时,它只会放置所有必需的依赖项和类(资源除外) )在可执行jar文件中。 You will then have to put the necessary resources on the programmed locations. 然后,您必须将必要的资源放在已编程的位置上。

I don't know what i am missing. 我不知道我错过了什么。 Its loading up my spring bean configuration outside the jar file properly (it doesnt crash during bootup). 它正确地将我的spring bean配置加载到jar文件之外(它在启动时不会崩溃)。 When i ran the executable through a terminal (java -jar App.jar), it doesnt contain any errors related to log4j2. 当我通过终端(java -jar App.jar)运行可执行文件时,它不包含任何与log4j2相关的错误。

When i branched, i only added 2 dependencies/libraries (down below). 当我分支时,我只添加了2个依赖项/库(下面)。 I have my logger currently setup such that it should log on the same folder as where the executable is running. 我当前设置了我的记录器,它应该记录与运行可执行文件的文件夹相同的文件夹。

Dependencies added since branch. 自分支以来添加的依赖项。

<dependency>
   <groupId>org.apache.sshd</groupId>
   <artifactId>sshd-core</artifactId>
   <version>1.4.0</version>
</dependency>

<dependency>
   <groupId>com.jcraft</groupId>
   <artifactId>jsch</artifactId>
   <version>0.1.54</version>
</dependency>

I'm using version 2.8.2 for log4j2 both api and core. 我正在使用版本2.8.2 for log4j2 api和core。

Here is my spring boot plugin script in my pom.xml file. 这是我的pom.xml文件中的spring boot插件脚本。

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
            <configuration>
                <classifier>spring-boot</classifier>
                <mainClass>
                        My Main Class here
                </mainClass>
                <layout>
                    JAR
                </layout>
            </configuration>
        </execution>
    </executions>
</plugin>

I'm not setting up the log4j2.xml in the code. 我没有在代码中设置log4j2.xml。 I just pray to the Gods it gets set properly during run time when i reference it. 我只是向众神祈祷,在我参考它时,它会在运行时正确设置。 ie

private static Logger log = LogManager.getLogger(CafQrCodeScannerMain.class);

and lastly here is my log4j2.xml file: 最后这是我的log4j2.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
            <File name="myFile" filename="${bundle:SomeFile:SomeFile.scanner.configuration.log.logFile}" immediateFlush="true" append="true">
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </File>
    </Appenders>
    <Loggers>
        <Root level="all">
            <AppenderRef ref="Console" />
            <AppenderRef ref="myFile"/>
        </Root>
    </Loggers>
</Configuration>

its referencing to a property file that has the content someFile.scanner.configuration.log.logFile=AppName.log 它引用具有内容someFile.scanner.configuration.log.logFile = AppName.log的属性文件

Any help would be appreciated. 任何帮助,将不胜感激。

You need a configuration for it named log4j2.xml put it under src/main/resources. 你需要一个名为log4j2.xml的配置把它放在src / main / resources下。 And check your pom.xml for a log4j dependency 并检查您的pom.xml以获取log4j依赖项

<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.8.2</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.8.2</version>
  </dependency>
</dependencies>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM