Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory

前端 未结 3 898
死守一世寂寞
死守一世寂寞 2020-12-19 18:13

some problems with java and slf4j Made project using idea and it is ok. But in case I try to make jar with gradle I have some problems.

build.gradle

         


        
相关标签:
3条回答
  • 2020-12-19 18:41

    JVM cannot find dependencies on classpath because they're not on classpath obviously. By default Gradle and Maven add just your classes to a jar and you have to specify paths to the dependencies manually with the -cp argument. If you want to build a fat jar you can use ShadowJar with Gradle and Shade with Maven.

    0 讨论(0)
  • 2020-12-19 18:41
    dependencies {
        compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
        testCompile group: 'junit', name: 'junit', version: '4.+'
        compile 'ch.qos.logback:logback-core:1.1.6'
        compile 'ch.qos.logback:logback-classic:1.1.6'
        compile 'org.slf4j:slf4j-api:1.7.18'
    }
    
    0 讨论(0)
  • 2020-12-19 18:44

    Thanks Michael for remembering about fat jar. After your comment tried to google: "gradle build fat jar" and after it modified my build.gradle

    jar {
        from {
            configurations.compile.collect {
                it.isDirectory() ? it : zipTree(it)
            }
        }
        manifest {
            attributes 'Main-Class': 'Test'
        }
    }
    
    0 讨论(0)
提交回复
热议问题