javaeclipsejarlog4j2uberjar

Is log4j compatible with jdk21?


When I try to build with ant single jar file which uses jar-in-jar-loader everything inside looks as expected. The manifest content is

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.10.14
Created-By: 21+35-LTS-2513 (Oracle Corporation)
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Rsrc-Main-Class: a.b.MyApp
Multi-Release: true
Rsrc-Class-Path: ./ lib/log4j/log4j-api-2.22.1.jar lib/log4j/log4j-cor
 e-2.22.1.jar lib/jdatepicker-1.3.4.jar
Class-Path: .

jar-in-jar-loader.zip is generated by eclipse 2023-12 which uses jdk21, all files seems to be in place in myApp.jar
However when I use java -jar myApp.jar I see

WARNING: Runtime environment or build system does not support multi-release JARs. This will impact location-based features.
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:62)
Caused by: java.lang.UnsupportedOperationException: No class provided, and an appropriate one cannot be found.
        at org.apache.logging.log4j.LogManager.callerClass(LogManager.java:585)
        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:610)
        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:597)
        at a.b.log.Log.getLogger(Log.java:48)
        at a.b.MyApp.handleInputParameters(MyApp.java:97)
        at a.b.MyApp.main(MyApp.java:33)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        ... 2 more

When I run the app under eclipse everything works properly.
Is that means log4j can't be used with jdk21 (I use Oracle version)?
How to check it? I tried on log4j web page and I found nothing (especially in changelog). I also tried to downgrade project to jdk17, also nothing.
How to solve this problem?


Solution

  • This is actually caused by a bug in the Eclipse jar-in-jar loader: cf. eclipse-jdt/eclipse.jdt.ui#1057.

    In the meantime you can:

    Edit: the 3.0.0 betas are not multi-release JARs, so they should not be affected by the problem.

    Edit 2: Since version 4.31 (Eclipse 2024-03), the jar-in-jar loader supports multi-release JARs.