【问题标题】:How to export a Spring Boot project to an executable standalone file?如何将 Spring Boot 项目导出为可执行的独立文件?
【发布时间】:2016-04-28 17:19:17
【问题描述】:

我在 Spring Tool Suite 中使用 Spring Boot 和 Gradle 创建了一个项目,但我真的不知道如何导出以使其工作。

我对 gradle 了解不多,只是从 maven 存储库添加依赖项的基础知识。所以在一些文章中说应用应用程序插件来完成任务,但我不知道如何设置配置文件以及如何创建可执行文件。

如果有人可以编写或链接一步一步的详细说明,将不胜感激。

这是我的 build.gradle 文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'

springBoot {
    mainClass = "com.rodamientosbulnes.objetivosventa.Application"
    executable = true
}

jar {
    baseName = 'objetivosventa'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework:spring-jdbc')
    compile('net.sourceforge.jtds:jtds:1.3.1')
    compile('org.apache.poi:poi-ooxml:3.13')
    compile('com.miglayout:miglayout-swing:4.2')
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

【问题讨论】:

    标签: java spring gradle spring-boot


    【解决方案1】:

    构建文件看起来不错,您只需要运行gradle build(或STS 中的Run As -> Gradle -> Gradle build)即可创建可运行的jar。

    有关 gradle 插件配置的更多详细信息,请访问 spring boot documentation site

    【讨论】:

    • 谢谢!!,我真是个白痴,我不知道它只是用构建任务创建的。
    【解决方案2】:

    Gradle 的应用程序插件不会为您创建一个可执行文件,但它可以创建一个发行版,其中包括所有依赖项、项目的 jar-artifact 和 2 个运行它的脚本(一个批处理文件和 linex 可执行文件) .

    您需要知道的主要事情是spring-boot 插件已经提供了您可能需要的application 插件中的所有任务。您可以找到here 的所有任务。您需要distZipinstallDist 将您的项目打包到发行版中。此任务将在您的 project-folder/build 文件夹下创建一个现成的项目分发。您可能会发现另一项有用的任务是buildRun,它将运行您的 spring-boot 应用程序,而无需将其打包到分发中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 2021-10-04
      • 1970-01-01
      • 2015-07-09
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      相关资源
      最近更新 更多