Error generating native image with Gluonfx for log4j and slf4j dependencies

1.3k views Asked by At

I'm trying to build a native image of a JavaFX app with Gluonfx, Micronaut and Graalvm

As logging framework I'm using log4j2 and log4j-slf4j-impl to route logs from slf4 to log4j.

Every time I want to run gluonfx:build I get multiples errors of log4j or slf4j classes initialization. Tried to add those classes to --initialize-at-build-time or initialize-at-run-time, but is just asking fo more and more each time.

This is my error:

 Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing org.slf4j.LoggerFactory.getILoggerFactory()
Parsing context:                                                                                                                                                                                
   at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:408)                                                                                                                          
   at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)                                                                                                                                  
   at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)                                                                                                                                  
   at com.myproject.demo.util.common.util.DefaultUpdateProgressLogger.<init>(DefaultUpdateProgressLogger.java:50)                                                                                  
   at com..myproject.demo.util.common.util.DefaultUpdateProgressLogger.<init>(DefaultUpdateProgressLogger.java:37)                                                                                  
                                                                                                                                                                                                 
    at com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:141)                                                                                                         
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.createTypeFlow(MethodTypeFlow.java:315)                                                                                                     
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureTypeFlowCreated(MethodTypeFlow.java:286)                                                                                              
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.addContext(MethodTypeFlow.java:107)                                                                                                         
    at com.oracle.graal.pointsto.flow.StaticInvokeTypeFlow.update(InvokeTypeFlow.java:428)                                                                                                       
    at com.oracle.graal.pointsto.PointsToAnalysis$2.run(PointsToAnalysis.java:598)                                                                                                               
    at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:195)                                                                                             
    at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:179)                                                                                    
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)                                                                                            
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)                                                                                                                 
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)                                                                                                
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)                                                                                                                  
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)                                                                                                             
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)                                                                                                    
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of org.apache.logging.slf4j.Log4jLoggerFactory are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=org.apache.logging.slf4j.Log4jLoggerFactory.                                                                                           
    at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.checkImageHeapInstance(ClassInitializationFeature.java:133)                                                          
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.replaceObject(AnalysisUniverse.java:575)                                                                                                  
    at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.replaceObject(AnalysisConstantReflectionProvider.java:217)                                                                 
    at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.interceptValue(AnalysisConstantReflectionProvider.java:188)                                                                
    at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readValue(AnalysisConstantReflectionProvider.java:102)                                                                     
    at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readFieldValue(AnalysisConstantReflectionProvider.java:81)                                                                 
    at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.util.ConstantFoldUtil$1.readValue(ConstantFoldUtil.java:51)                                                                           
    at jdk.internal.vm.compiler/org.graalvm.compiler.core.common.spi.JavaConstantFieldProvider.readConstantField(JavaConstantFieldProvider.java:84)                                              
    at com.oracle.svm.hosted.ameta.AnalysisConstantFieldProvider.readConstantField(AnalysisConstantFieldProvider.java:72)                                                                        
    at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.util.ConstantFoldUtil.tryConstantFold(ConstantFoldUtil.java:47)                                                                       
    at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.java.LoadFieldNode.asConstant(LoadFieldNode.java:166)                                                                                 
    at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.java.LoadFieldNode.canonical(LoadFieldNode.java:132)                                                                                  
    at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.java.LoadFieldNode.canonical(LoadFieldNode.java:123)                                                                                  
    at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.java.LoadFieldNode.canonical(LoadFieldNode.java:68)  

And the log4j2 dependencies in my POM file:

        <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.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>${log4j.version}</version>
        </dependency>

Normally starts to fail after add the slf4j binding 'log4j-slf4j-impl'

UPDATE After running gluonfx:runagent goal I get these warnings and the above error remains:

Warning: Could not register method org.apache.commons.logging.impl.Log4JLogger.<init>(String) for reflection. Reason: java.lang.NoClassDefFoundError: org/apache/log4j/Priority.                 
Warning: Could not resolve org.apache.log4j.Appender for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.Appender.                                          
Warning: Could not resolve org.apache.log4j.AppenderSkeleton for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.AppenderSkeleton.                          
Warning: Could not resolve org.apache.log4j.Category for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.Category.                                         
Warning: Could not resolve org.apache.log4j.CategoryKey for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.CategoryKey.                                    
Warning: Could not resolve org.apache.log4j.FileAppender for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.FileAppender.                                  
Warning: Could not resolve org.apache.log4j.Layout for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.Layout.                                              
Warning: Could not resolve org.apache.log4j.Level for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.Level.                                                
Warning: Could not resolve org.apache.log4j.Logger for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.Logger.                                              
Warning: Could not resolve org.apache.log4j.PatternLayout for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.PatternLayout.                                
Warning: Could not resolve org.apache.log4j.Priority for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.Priority.                                          
Warning: Could not resolve org.apache.log4j.RollingFileAppender for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.RollingFileAppender.                    
Warning: Could not resolve org.apache.log4j.WriterAppender for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.WriterAppender.                              
Warning: Could not resolve org.apache.log4j.helpers.Loader for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.helpers.Loader.                              
Warning: Could not resolve org.apache.log4j.spi.OptionHandler for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.spi.OptionHandler. 
0

There are 0 answers