SpringBoot JAR to WAR
add the following line to the pom.xml
<packaging>war</packaging>then add the following within the dependencies
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
...<scope>provided</scope> means the dependency:
- are provided at runtime by JDK or a container
- are available only at compile-time and in the test classpath of the project
Running SpringBoot’s Embedded Tomcat Servlet
even though the pom.xml specifies a war package, we can still compile and run the SpringBoot application with it’s embedded tomcat servlet
mvn clean compilemvn spring-boot:run
Running Packaged WAR on External Tomcat Servlet
now let’s package the SpringBoot application as a .war file and deploy it on an external Tomcat servlet
mvn clean package- retrieve
spring-boot-war-example.warfile fromtarget/directory - place it into tomcat’s
libexec/webapps - start tomcat server
- open browser to http://localhost:8080/spring-boot-war-example
- if you see
hello worldthen success!