Differences between jar and war in Spring Boot?

后端 未结 5 1715
悲哀的现实
悲哀的现实 2020-12-14 07:05

I\'m about to build my first website in Java with Spring Framework using Spring Boot and it\'s much easier to build it in jar, but I have a few questions about

5条回答
  •  孤街浪徒
    2020-12-14 07:23

    Running spring-boot application as fat *.jar

    It is possible to build so called fat JAR that is executable *.jar file with embedded application container (Tomcat as default option). There are spring-boot plugins for various build systems. Here is the one for maven: spring-boot-maven-plugin

    To execute the kind of fat *.jar you could simple run command:

    java -jar *.jar
    

    Or using spring-boot-maven goal:

    mvn spring-boot:run
    

    Building spring-boot application as *.war archive

    The other option is to ship your application as old-fashioned war file. It could be deployed to any servlet container out there. Here is step by step how-to list:

    1. Change packaging to war (talking about maven's pom.xml)
    2. Inherit main spring-boot application class from SpringBootServletInitializer and override SpringApplicationBuilder configure(SpringApplicationBuilder) method (see javadoc)
    3. Make sure to set the scope of spring-boot-starter-tomcat as provided

    More info in spring-boot documentation

提交回复
热议问题