可执行Spring Boot 2 jar [英] Executable Spring Boot 2 jar

查看:113
本文介绍了可执行Spring Boot 2 jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to install my Spring Boot application. As first step I try to create an executable jar as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html

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

However if I extend my gradle script (I'm using gradle 4.4) with the lines:

springBoot {
    executable = true
}

然后构建失败并显示错误:

Then the build fails with an error:

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 1.x的参考文档,但您使用的是Spring Boot 2.x,其中Gradle插件已进行了相当多的更新.广泛地.现在,它具有自己的单独的参考文档.

You've linked to the reference documentation for Spring Boot 1.x, but you're using Spring Boot 2.x where the Gradle plugin has been updated quite extensively. It now has its own, separate reference documentation.

在该参考文档中,它

In that reference documentation, it describes how to create a fully executable jar file that includes the prepended launch script:

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

Spring Boot provides support for fully executable archives. An archive is made fully executable by prepending a shell script that knows how to launch the application. On Unix-like platforms, this launch script allows the archive to be run directly like any other executable or to be installed as a service.

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

To use this feature, the inclusion of the launch script must be enabled:

bootJar {
    launchScript()
}

这篇关于可执行Spring Boot 2 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆