Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executable Spring Boot 2 jar

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

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.

My build script is the following:

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')
}
like image 687
Vmxes Avatar asked Dec 12 '17 13:12

Vmxes


People also ask

What is spring boot executable jar?

A Spring Boot application is typically built into a single executable JAR archive. It contains all dependencies inside, packaged as nested JARs. Likewise, a Spring Boot project is usually built as an executable JAR file by a provided maven plugin that does all the dirty work.

What is the difference between jar and executable jar?

FYI: In simple terms, the difference between a JAR file and a Runnable JAR is that while a JAR file is a Java application which requires a command line to run, a runnable JAR file can be directly executed by double clicking it.

Can I run spring boot executable jar from commandline?

In one word, we call it a methodology where an entire Spring Boot application is built into a single executable Jar archive and includes all the dependencies, packaged as nested Jars. The plugins in Maven does all the dirty work and provides you with the FAT Jar, which can be run easily using the command of java -jar.


1 Answers

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 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()
}
like image 145
Andy Wilkinson Avatar answered Oct 12 '22 23:10

Andy Wilkinson