Spring boot uses gradle to package all dependent jar packages

 

 Using spring boot to create a simple project, the jar dependency is solved by gradle, and it can run normally in eclipse, and then use gradle build to make a jar package. It is found that there are only dozens of k, and java -jar xxx.jar cannot run. This problem occurs because the dependent jar package is not entered.

Use the following script to enter the dependent jar package

 

buildscript {

    ext {

        springBootVersion = '1.4.0.RELEASE'

    }

    repositories {

        mavenCentral()

    }

    dependencies {

        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")

    }

}

 

apply plugin: 'java'

apply plugin: 'eclipse'

apply plugin: 'spring-boot'

 

Use buildscript to add the spring-boot-gradle-plugin plug-in, import the spring-boot packaging plug-in through apply plugin: 'spring-boot', and then right-click gradle build in build.gradle to generate the packaged file in the build file.

 

The directories in the packaged jar package are as follows:

 BOOT-INF contains a lib directory and a classes directory

 

The lib directory is the outsourced jar package that the project package depends on, and the classes folder is its own class file.

There are many other plug-ins on the Internet, I have tried several, but they are not very easy to use. The jar package that is typed is to type the class that depends on the jar package into its own jar package. There is no such clarity, and it is run with java -jar. Missing class will be reported.

 

 


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326044310&siteId=291194637