[JAVA] Differences between Spring Initializr packaging JAR and WAR

Generate web application with Spring Initializr

Generate a Web application template with the following settings in Spring Initializr.

I generated the Packaging items as Jar and War, respectively, and took the difference with the diff command.

Difference between Jar and War

$ diff -r jar war
diff -r jar/demo/build.gradle war/demo/build.gradle
4a5
> 	id 'war'
16a18
> 	providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
Only in war/demo/src/main/java/com/example/demo: ServletInitializer.java

Gradle War Plugin

Gradle's War Plugin has been added to the War application.

id 'war'

War Plugin is a plugin that adds a task to generate a war file.

Reference: The War Plugin

Spring Boot Tomcat Starter

Spring Boot Tomcat Starter is specified in providedRuntime for War applications.

providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'

This uses the embedded Tomcat when running in the local environment, but by specifying providedRuntime, the embedded Tomcat is not included when the war file is generated. Reference: Maven Repository: org \ .springframework \ .boot »spring \ -boot \ -starter \ -tomcat

ServletInitializer

A ServletInitializer has been added to the War application.

package com.example.demo;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(DemoApplication.class);
  }

}

This will be a class that implements the WebApplicationInitializer interface required in the environment where the war file is deployed and operated. Reference: [SpringBootServletInitializer \ (Spring Boot Docs 2 \ .2 \ .1 \ .RELEASE API )](https://docs.spring.io/spring-boot/docs/2.2.1.RELEASE/api/org/ springframework / boot / web / servlet / support / SpringBootServletInitializer.html)

Recommended Posts

Differences between Spring Initializr packaging JAR and WAR
Differences between IndexOutOfBoundsException and ArrayIndexOutOfBoundsException
Differences between "beginner" Java and Kotlin
Differences between Applet class and JApplet class
Differences between Java and .NET Framework
Differences between preface and postfix of operators
[Java] Differences between instance variables and class variables
How to create a server executable JAR and WAR with Spring gradle
Differences between Ruby strings and symbols [Beginner]
[Understanding] Differences between hashes and arrays in Ruby
Summarize the differences between C # and Java writing
Ruby: Differences between class methods and instance methods, class variables and instance variables
[Ruby] Difference between receiver and object. Differences between Ruby objects and JS objects
Differences between Ruby syntax error statements in Ruby and binary
Differences between browser sessions and cookies and Rails session and cookies methods
Difference between Spring AOP and library proxy target class
Differences between Fetch Type LAZY and EAGER in Hibernate
Hello World comparison between Spark Framework and Spring Boot