log4j2 java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager

前端 未结 2 1279
不思量自难忘°
不思量自难忘° 2021-02-05 23:18

I am using log4j 2.3 in my java application. I added the dependency via maven.
When running the program in eclipse everything work fine, but when I package it with maven and

2条回答
  •  时光说笑
    2021-02-06 00:03

    When you are running your application jar from command line your dependent jar are not available at runtime. You need to include any of these two plugins to pom.xml so have your dependencies available at runtime.

    Using: maven-shade-plugin

    
            org.apache.maven.plugins
            maven-shade-plugin
            2.4.1
            
              
                package
                
                  shade
                
                
                  
                    
                      org.sonatype.haven.HavenCli
                    
                  
                
              
            
          
    

    Using:maven-dependency-plugin

    
        org.apache.maven.plugins
        maven-dependency-plugin
        2.8
        
            
                 copy-dependencies
                 package
                 
                     copy-dependencies
                 
                 
                     ${project.build.directory}/lib
                 
            
         
    
    

    When you will execute the mvn package it will generate uber jar / or copy the dependencies to outputDirectory. I will prefer maven-shade-plugin to generate one jar will all dependencies.

提交回复
热议问题