我是靠谱客的博主 羞涩鸭子,最近开发中收集的这篇文章主要介绍gradle springboot项目生成可执行的jar包,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

gradle springboot项目生成可执行的jar包

目录

官方文档: packaging executeable archives

配置:build.gradle

命令

运行jar包:


使用gradle的spirngboot项目,要如何生成jar包?

 

官方文档: packaging executeable archives

 

部分截图:

依赖

dependencies {

      implementation 'org.springframework.boot:spring-boot-starter-web'

      providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'

}

 

整合官网介绍的内容,来进行配置

 

配置:build.gradle

version = '0.0.1-SNAPSHOT' // 版本
bootJar {

    manifestContentCharset 'utf-8'

    metadataCharset 'utf-8'

    archivesBaseName = 'report-config' // jar包名

    manifest {

        attributes "Manifest-Version": 1.0,

                'Start-Class': 'com.web.report. ReportApplication' //  springboot项目的启动类

    }

}

jar.enabled = true

bootJar.enabled = true
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-tomcat'

    // other

}

 

命令

gradlew clean bootJar

这样就可以生成得到可运行的jar包了

 

运行jar包:

windows下使:

java -jar xxx.jar

 

总结:

    去看官网的内容,里面有详细的介绍,然后结合自己的需求,去组合整理,就可以得到想要的内容。另外一种用shadowJar生成jar包的方式,参考  Gradle 把引用的内容,一起打包编译(gradlew clean ),生成独立jar包

 

 

最后

以上就是羞涩鸭子为你收集整理的gradle springboot项目生成可执行的jar包的全部内容,希望文章能够帮你解决gradle springboot项目生成可执行的jar包所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部