Search code examples
mavenjavafxlog4j2multi-module

javafx - log4j2 issue when running the app from builded custom runtime image


i have created multi module javafx app where I am using log4j2 for logging. The build tool is maven.

When I will run it mvn clean javafx:run Everything works as expected - no issues.

But when I want to run the created runtime image (created with mvn clean compile javafx:jlink) I can see that the logging is not working and I am getting the following error in the console:

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

According to my searches it looks like an issue with log4j2 being non-modular where the solution was created for gradle (badass-jlink-plugin.beryx.org), unfortunately, I am not allowed to use gradle and I did not find anything similar for maven. But I might be wrong...

Can anybody help?

here is the pom file:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>some.group</groupId>
    <artifactId>artifact</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.2</version>
        </dependency>
        <dependency>
            <groupId>jakarta.activation</groupId>
            <artifactId>jakarta.activation-api</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.13.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.13.3</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <stripDebug>true</stripDebug>
                    <compress>2</compress>
                    <noHeaderFiles>true</noHeaderFiles>
                    <noManPages>true</noManPages>
                    <launcher>myApp</launcher>
                    <jlinkImageName>myApp</jlinkImageName>
                    <jlinkZipName>myApp</jlinkZipName>
                    <mainClass>some.group.artifact.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

and here is the module info:

module some.group.artifact {
    requires javafx.controls;
    requires javafx.fxml;
    requires transitive javafx.graphics;
    requires javafx.base;
    requires java.xml.bind;
    requires com.sun.xml.bind;
    requires org.apache.logging.log4j;

    opens some.group.artifact.controllers to java.xml.bind, javafx.fxml;
    opens some.group.artifact to javafx.fxml;
    
    exports some.group.artifact.controllers;
    exports some.group.artifact;
}

Here is the log4j2 properties file saved under src/main/resources folder:

status = error
name = Log4j2PropertiesConfig
 
# change log file name as per your requirement
property.filename = ${sys:user.home}/logs
 
appenders = console, rolling
 
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
#appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss} [%t] %c{1}- %msg%n 
appender.console.layout.pattern = %d [%-5level] [%t] %logger{-2} - %msg%n%throwable
 
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}/log.log
appender.rolling.filePattern = ${filename}/history/%d{yyyy-MM-dd-HH-mm-ss}.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %p %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.startup.type = OnStartupTriggeringPolicy
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10Mb
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 100
 
loggers = rolling
logger.rolling.name = some.group.artifact
logger.rolling.level = info
logger.rolling.additivity = true
logger.rolling.appenderRef.rolling.ref = RollingFile

rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT

Thank you for your time and effort!


Solution

  • I fixed it by switching to gradle and using badass-jlink-plugin.beryx.org ...