小编典典

可执行Spring Boot 2 jar

spring-boot

我尝试安装我的Spring
Boot应用程序。第一步,我尝试按如下所述创建一个可执行jar:https
//docs.spring.io/spring-boot/docs/current/reference/html/deployment-
install.html

但是,如果我用以下行扩展gradle脚本(我正在使用gradle 4.4):

springBoot {
    executable = true
}

然后,构建因错误而失败:

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\spring\app\build.gradle' line: 15

* What went wrong:
A problem occurred evaluating root project 'app'.
> Could not find method springBoot() for arguments [build_3mwux4us8m2jn9yfcogqkbm4y$_run_closure1@506b241f] on root project 'app' of type org.gradle.api.Project.

我的构建脚本如下:

buildscript {
    ext {
        springBootVersion = '2.0.0.M6'
    }
    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}")
    }
}

springBoot {
    executable = true
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


group = 'com.test'
version = '0.0.3'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
    maven { url 'https://repo.spring.io/libs-release' }
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    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-validation')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.data:spring-data-envers:2.0.2.RELEASE')
    compile('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect')
    compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4")
    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')
}

阅读 326

收藏
2020-05-30

共1个答案

小编典典

您已经链接到Spring Boot 1.x的参考文档,但是您正在使用Spring Boot
2.x,其中Gradle插件已进行了相当广泛的更新。现在,它具有自己的单独的参考文档

在该参考文档中,它描述了如何创建包含可执行启动脚本的完全可执行的jar文件:

Spring
Boot提供了对完全可执行存档的支持。通过在外壳程序脚本之前添加知道如何启动该应用程序的shell脚本,可以使存档完全可执行。在类似Unix的平台上,此启动脚本允许归档文件像任何其他可执行文件一样直接运行,或作为服务安装。

要使用此功能,必须启用启动脚本的包含:

bootJar {
    launchScript()
}
2020-05-30