【问题标题】:Executable Spring Boot 2 jar可执行 Spring Boot 2 jar
【发布时间】:2018-05-26 05:23:10
【问题描述】:

我尝试安装我的 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')
}

【问题讨论】:

    标签: spring-boot gradle


    【解决方案1】:

    尝试手动执行以下 gradle 任务:

    • gradlew 罐子
    • gradlew bootRepackage

    之后你应该有你的捆绑胖罐。 (我就是这样解决的)

    【讨论】:

    • @BaurMarius 此解决方案仅适用于 Spring Boot 1.x,因为 bootRepackage 任务已被 Spring Boot 2.0 的 gradle 插件中的 bootJar 替换。 Spring Boot 2.0 Migration Guide 解释了这一变化
    【解决方案2】:

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

    在该参考文档中,describes 如何创建包含前置启动脚本的完全可执行 jar 文件:

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

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

    bootJar {
        launchScript()
    }
    

    【讨论】:

    • Spring Boot Gradle 的链接很有帮助。
    猜你喜欢
    • 2014-12-18
    • 2018-08-27
    • 2017-11-21
    • 2017-01-20
    • 1970-01-01
    • 2016-09-28
    • 2017-07-24
    • 2014-11-27
    • 1970-01-01
    相关资源
    最近更新 更多