java.lang.NoClassDefFoundError: when trying to run jar

前端 未结 2 2009
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-11 18:51

I have a spring boot project using gradle

apply plugin: \'java\'
apply plugin: \'idea\'
apply plugin: \'jetty\'
apply plugin: \'war\'
apply plugin: \'org.spr         


        
2条回答
  •  北海茫月
    2021-01-11 19:41

    1. Define a task called fatJar in build.gradle:
    jar {
        baseName = 'base-name'
        version = '0.1.0'
        manifest {
            attributes(
                    'Main-Class': 'com.github:'
            )
        }
    }
    
    task fatJar(type: Jar) {
        manifest.from jar.manifest
    //    classifier = 'all'
        from {
            configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
        } {
            exclude "META-INF/*.SF"
            exclude "META-INF/*.DSA"
            exclude "META-INF/*.RSA"
        }
        with jar
    }
    
    artifacts {
        archives fatJar
    }
    
    1. Run gradle fatJar or ./gradlew fatJar to generate a jar file with all dependencies, which can run independently but may be pretty large in size (that's why it's called a fat jar).

提交回复
热议问题