java - 使用 gradle 从 spring boot 1.5.3 构建可执行的 .jar
问题描述
我有一个 spring boot 项目(1.5.3 版本)并使用 gradle 4.4。我将构建一个 .jar 可执行文件以在 linux 服务器上安装服务。但我在生成可执行的 .jar 文件时遇到问题。
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
//springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'
springBoot {
executable = true
}
group = 'com.mygroup'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile("org.springframework.boot:spring-boot-starter-web")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4')
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.371'
compile group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.370'
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
testCompile('com.jayway.jsonpath:json-path')
}
我如何生成.jar?
解决方案
缺少启动 jar 的依赖项。
在 build.gradle 中添加:
bootJar {
baseName = 'application-name'
version = '1.0.0'
}
终端中的命令:
gradle bootjar
推荐阅读
- java - Apache POI Excel 图表在 Mac 上消失,但在 Windows/Linux 上没有
- agda - 如何在有前提的情况下制作 Adga 函数
- javascript - 未捕获的 ReferenceError:未在 HTMLInputElement.onchange 中定义 readURL
- java - LWJGL 3 正交相机实现导致闪烁的播放器实体
- java - Atomic 中的 Java 计算
- database - 设计 NoSQL 数据表
- python - 在这个流循环中,我应该在哪里放置 float() 或任何类型的字符串到数字函数?
- javascript - 如何使用 Plyr JS 在视频播放器中添加下载按钮?
- dns - (碘)将 dns0 流量路由到 eth0
- python - Keras:在 flow_from_directory() 中使用多个目录