Jim
Jim

Reputation: 383

Generating war for spring boot application

I have been following the tutorial provided by spring and cannot seem to understand why my .war file is empty. Click here to see/download the code. The end goal is to download this file, build a .war file and then deploy it to my tomcat server. I've added the following to the build.gradle

apply plugin: "war"

but this only generates a war that contains zero class files.

build.gradle

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

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'gs-spring-boot'
     version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    // tag::actuator[]
    compile("org.springframework.boot:spring-boot-starter-actuator")
    // end::actuator[]
    // tag::tests[]
    testCompile("org.springframework.boot:spring-boot-starter-test")
    // end::tests[]
 }

Upvotes: 0

Views: 2387

Answers (1)

chenrui
chenrui

Reputation: 9866

For the tutorial code, you need to do two things:

  1. war plugin for packaging spring-boot ref:

    apply plugin: 'war'
    
    war {
        baseName = 'gs-spring-boot'
        version =  '0.1.0'
    }    
    
  2. Create a deployable war file spring-boot ref:

    @SpringBootApplication
    public class Application extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
    

And also specify the tomcat dependency as provided:

dependencies {
    // …
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    // …
}

Here is my commit reference and result: result

Upvotes: 5

Related Questions