Spring Boot Gradle Package executable jar file!

Source: Internet
Author: User
Tags jcenter

Build your project with Gradle, inherit Ant's Flexible and Maven lifecycle management, no longer use XML as a configuration file format, and use the DSL format to make the script more concise.
Build your environment:

  1. jdk1.6 above, use 1.8 here
  2. Gradle 4.4.1
  3. Springboot
  4. Idea
First, download and install Gradle

Gradle official website

 Gradle official website

1. Download Gradle

Download Gradle

 gradle version Download

2. Unzip the Gradle

Unzip to the directory you want to store after downloading

 Gradle Decompression

3. Setting Gradle Environment Variables
    1. Create an environment variable gradle_home and point to the installation path of your grdle:
      gradle Environment variables
    2. Add%gradle_home%\bin to your PATH environment variable:
      gradle Environment variables
4. Detection Configuration Gradle Configuration DetectionIi. creation of the project

1. Select Gradle, tick Java, select SDK (jdk1.8)

 Creating a Project 1
2. Setting GroupID and Artifactid
 Creating a Project 2
3. Select our local gradle and set the JVM
! [Create Item 3]] (//upload-images.jianshu.io/upload_images/7228029-4560fdecebd1979d.png?imagemogr2/auto-orient/strip% 7cimageview2/2/w/1240)

iii. Configuration Items

1. The SRC folder is not generated automatically after the project is created.

 Configuration Item 1
we create our own folders
 Configuration Item 2
2. Configure Build.gradle

allprojects {Group' Com.chen ' version' 1.0-snapshot ' repositories {maven {URL' http://maven.aliyun.com/nexus/content/groups/public/'}}}buildscript {ext {springioversion =' 1.0.0.RELEASE ' springbootversion =' 1.5.9.RELEASE '} repositories {jcenter () mavenlocal () mavencentral () Maven {URL"Http://repo.spring.io/release"} maven {URL"Http://repo.spring.io/milestone"} maven {URL"Http://repo.spring.io/snapshot"} maven {URL"Https://plugins.gradle.org/m2/"}} dependencies {Classpath"Io.spring.gradle:dependency-management-plugin:${springioversion} "Classpath"Org.springframework.boot:spring-boot-gradle-plugin:${springbootversion} "}}tasks.withtype (javacompile) {options.encoding ="UTF-8"}apply plugin:' Idea ' Apply plugin:' Java ' Apply plugin:' Spring-boot ' Apply plugin:' io.spring.dependency-management ' sourcecompatibility = 1.8targetCompatibility = 1.8jar {baseName =' Gradle-demo ' Version =' 0.0.1 ' manifest {attributes"Manifest-version": 1.0,' Main-class ': ' Com.chen.GradleDemoApplication '}} repositories {jcenter () mavenlocal () mavencentral ()}dependencymanagement {imports {Mavenbom  ' io.spring.platform:platform-bom:brussels-sr6 ' Mavenbom  ' Org.springframework.cloud:spring-cloud-dependencies:brixton.sr4 '}}ext {junitversion =  4.12 '}dependencies {compile  ' org.springframework:spring-core ' compile  Org.springframework.boot:spring-boot-autoconfigure ' compile  Org.springframework.boot: Spring-boot-starter-tomcat ' testcompile  Org.springframework.boot: Spring-boot-starter-test ' testcompile  "Junit:junit:${ Junitversion} "}           

3. Create Springboot startup class

 @Controller  @SpringBootApplication public class  gradledemoapplication {public  Static void main (String[] args) { Springapplication.run (Gradledemoapplication.class, args); }  @ResponseBody  @GetMapping ( "/") public String hello  () {return  "Hello world!";}}   
Iv. Start-up project
    1. Build Project First
      Startup Project 1
      Startup Project 2
    2. Launch Project, click Bootrun
      Startup Project 3
      Startup Project 4
v. Test Project Test ProjectSix, packaging jar project

Packaging Items 1
 Packaging Items 2

Vii. Execution Jar

Execute command: Java-jar Build/libs/gradle-demo-0.0.1.jar

 Execute Jar

Catalpaflat
Links: https://www.jianshu.com/p/9231b1f598c5
Source: Jane book
copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

Spring Boot Gradle Package executable jar file!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.