首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可执行Spring 2 jar

可执行Spring 2 jar
EN

Stack Overflow用户
提问于 2017-12-12 13:39:21
回答 2查看 6.4K关注 0票数 6

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

但是,如果我将gradle脚本(我使用gradle 4.4)扩展到行中:

代码语言:javascript
复制
springBoot {
    executable = true
}

然后生成失败,并出现错误:

代码语言:javascript
复制
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.

我的构建脚本如下:

代码语言:javascript
复制
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')
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-12-12 15:24:51

您已经链接到SpringBoot1.x的参考文档,但是您正在使用SpringBoot2.x,其中Gradle插件已经得到了相当广泛的更新。现在它有了自己的、独立的参考文献

在该参考文档中,描述如何创建一个完全可执行的jar文件,其中包括预先准备好的启动脚本:

Spring提供了对完全可执行档案的支持。存档是通过预先添加一个知道如何启动应用程序的shell脚本而使其完全可执行的。在类似Unix的平台上,这个启动脚本允许像任何其他可执行文件一样直接运行存档,或者作为服务安装。 若要使用此特性,必须启用包含启动脚本的功能: bootJar { launchScript() }

票数 15
EN

Stack Overflow用户

发布于 2017-12-12 13:45:08

尝试手动执行以下分级任务:

  • 梯度罐
  • 梯度bootRepackage

之后你就应该把你的包好了。(我就是这样解决的)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47774075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档