Hallo,
ich kämpfe gerade mit log4j und jlink. Wenn ich das Projekt ausführe wird, werden Meldungen über log4j in den Logfile geschrieben. Nachdem ich ein Image erzeugt habe, bekomme ich beim Starten die Fehlermeldung "ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...".
Das Image habe ich mit Maven erzeugt.
Anscheinend fehlt ein Eintrag in dem POM-File. Das gleiche Problem hatte ich auch schon mit Logback.
ich kämpfe gerade mit log4j und jlink. Wenn ich das Projekt ausführe wird, werden Meldungen über log4j in den Logfile geschrieben. Nachdem ich ein Image erzeugt habe, bekomme ich beim Starten die Fehlermeldung "ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...".
Das Image habe ich mit Maven erzeugt.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>net.schusser</groupId>
<artifactId>testbed</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<!-- Application Properties -->
<link.name>${project.artifactId}</link.name>
<launcher>${project.artifactId}</launcher>
<appName>${project.artifactId}</appName>
<main.class>net.schusser.testbed.App</main.class>
<main.module>Testbed</main.module>
<java.version>17</java.version>
<required.maven.version>3.6.3</required.maven.version>
<!-- Dependency versions -->
<lombok.version>1.18.24</lombok.version>
<jetbrains.annotations.version>23.0.0</jetbrains.annotations.version>
<junit.version>5.9.1</junit.version>
<javafx.version>19</javafx.version>
<controsfx-version>11.1.2</controsfx-version>
<log4j.version>2.19.0</log4j.version>
<!-- Plugin dependencies -->
<maven.clean.plugin>3.2.0</maven.clean.plugin>
<maven.compiler.plugin>3.10.1</maven.compiler.plugin>
<maven.dependency.plugin>3.3.0</maven.dependency.plugin>
<maven.deploy.plugin>3.0.0-M2</maven.deploy.plugin>
<maven.enforcer.plugin>3.1.0</maven.enforcer.plugin>
<maven.install.plugin>3.0.0-M1</maven.install.plugin>
<maven.jar.plugin>3.2.2</maven.jar.plugin>
<maven.resources.plugin>3.2.0</maven.resources.plugin>
<maven.site.plugin>4.0.0-M1</maven.site.plugin>
<maven.surfire.plugin>3.0.0-M6</maven.surfire.plugin>
<moditect.maven.plugin>1.0.0.RC2</moditect.maven.plugin>
<jpackage.maven.plugin>0.1.3</jpackage.maven.plugin>
<maven.pmd.version>3.16.0</maven.pmd.version>
<pmd.version>6.49.0</pmd.version>
<codehaus.version.plugin>2.11.0</codehaus.version.plugin>
<spotbugs.maven.plugin>4.7.2.0</spotbugs.maven.plugin>
<spotbugs.version>4.7.2</spotbugs.version>
<!-- other properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>${controsfx-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- ************************************************************* -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<!-- Dependency used for @NotNull / @Nullable -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${jetbrains.annotations.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven.enforcer.plugin}</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>${required.maven.version}</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin}</version>
<configuration>
<release>${java.version}</release>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven.clean.plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven.deploy.plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${maven.install.plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven.resources.plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${maven.site.plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surfire.plugin}</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven.dependency.plugin}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>${main.module}/${main.class}</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>${moditect.maven.plugin}</version>
<executions>
<execution>
<id>add-module-info-to-dependencies</id>
<phase>package</phase>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<overwriteExistingFiles>true</overwriteExistingFiles>
<!-- Beispiel wie eine Dependency ohne module-info diese bekommen kann! -->
<!--
<modules>
<module>
<artifact>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</artifact>
<moduleInfo>
<name>org.json</name>
</moduleInfo>
</module>
</modules>
-->
<module>
<mainClass>${main.class}</mainClass>
<moduleInfoFile>${project.build.sourceDirectory}/module-info.java</moduleInfoFile>
</module>
<jdepsExtraArgs>
--ignore-missing-deps
</jdepsExtraArgs>
</configuration>
<goals>
<goal>add-module-info</goal>
</goals>
</execution>
<execution>
<id>create-runtime-image</id>
<phase>package</phase>
<goals>
<goal>create-runtime-image</goal>
</goals>
<configuration>
<modulePath>
<path>${project.build.directory}/modules</path>
</modulePath>
<modules>
<module>${main.module}</module>
</modules>
<launcher>
<name>${launcher}</name>
<module>${main.module}</module>
</launcher>
<compression>2</compression>
<jarInclusionPolicy>APP_WITH_DEPENDENCIES</jarInclusionPolicy>
<stripDebug>true</stripDebug>
<outputDirectory>${project.build.directory}/jlink-image</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.akman</groupId>
<artifactId>jpackage-maven-plugin</artifactId>
<version>${jpackage.maven.plugin}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jpackage</goal>
</goals>
<configuration>
<name>${appName}</name>
<type>IMAGE</type>
<runtimeimage>${project.build.directory}/jlink-image</runtimeimage>
<module>${main.module}/${main.class}</module>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven.pmd.version}</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>${pmd.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>${pmd.version}</version>
</dependency>
</dependencies>
<configuration>
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>${java.version}</targetJdk>
<linkXRef>false</linkXRef>
<rulesets>
<ruleset>pmd-ruleset.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<!-- pmd does not stop build when violations are found -->
<goal>pmd</goal>
<!-- check stops the build when violations are found -->
<!-- <goal>check</goal> -->
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>${codehaus.version.plugin}</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
<goal>display-property-updates</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Java:
module Testbed {
requires javafx.base;
requires transitive javafx.graphics;
requires javafx.controls;
requires javafx.web;
requires javafx.fxml;
requires org.controlsfx.controls;
requires org.apache.logging.log4j;
opens net.schusser.testbed to javafx.fxml;
exports net.schusser.testbed;
}
Java:
package net.schusser.testbed;
import java.io.IOException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
public class App extends Application {
static final Logger logger = LogManager.getLogger(App.class);
private Stage primaryStage;
private BorderPane rootLayout;
@Override
public void start(Stage primaryStage) {
try {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Testbed");
//this.primaryStage.getIcons().add(logo);
initRootLayout();
} catch(Exception e) {
e.printStackTrace();
}
}
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(App.class.getResource("main.fxml"));
rootLayout = (BorderPane) loader.load();
MainController controller = loader.getController();
controller.setMainApp(this);
Scene scene = new Scene(rootLayout);
scene.getStylesheets().add(App.class.getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent e) {
if(!controller.canClose()){
e.consume(); // prevent closing
}
}
});
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
logger.debug("Start App");
launch(args);
}
}
Anscheinend fehlt ein Eintrag in dem POM-File. Das gleiche Problem hatte ich auch schon mit Logback.