giorgiline
giorgiline

Reputation: 1371

How to export a Spring Boot project to an executable standalone file?

I have created a project in Spring Tool Suite with Spring Boot and Gradle, and I really don't know how to export to make it work.

I don't know much about gradle, just the basics to add dependencies from the maven repository. So in some articles says to apply the application plugin to do the task, but I don't know how to set up the configuration file and how to create the executable.

If anyone could write or link a step by step detailed explanation on how to do it, it would be very much appreciated.

This is my build.gradle file:

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'
}

Upvotes: 2

Views: 7350

Answers (2)

Stanislav
Stanislav

Reputation: 28106

Gradle's application plugin doesn't make a single execitable for you, but it can create a distribution, which includes all the dependencies, jar-artifact for your project and 2 scripts to run it (one batch-file and linex executable).

The main thing you need to know, is that spring-boot plugin already provide all the task from application plugin you may need. All the task you can find here. You need distZip or installDist to package your project to the distribution. This task will create a ready project distribution under your project-folder/build folder. One more task you may find usefull is buildRun which will run you spring-boot application without package it into distribution.

Upvotes: 1

mzc
mzc

Reputation: 3355

Build file looks fine, you only need to run gradle build (or Run As -> Gradle -> Gradle build in the STS) to create the runnable jar.

More details about configuration of the gradle plugin are available on spring boot documentation site.

Upvotes: 2

Related Questions