Spring Boot – Migrating From Jar to War | Maven

Spring Boot - From Jar to War

In this article I’ll enumerate the few steps to migrate Spring Boot Project – From Jar to War File. Let me start with – if you’ve started your project from the scratch with the idea of building a war file, you could select this option on https://start.spring.io/. This way you will not need any additional changes. But, if you’ve selected the jar building option, or you’ve downloaded a project from the Internet with the  default Maven builder – you could use the following changes. If your building engine is Gradle, the steps probably will be similar.

    •  You need a child of <parent> that is <packaging>war</packaging>
    • If you don’t have the following dependency, add it. It is the servlet container dependencies:
  • A Default Spring Boot Java Main Class usually has a public static void main method, it usually has @SpringBootApplication. It may has @ComponentScans, @EntityScan, @EnableJpaRepositories – with scanning java packages or some other parameters. For a Java Spring Boot Web App to start as Web App the main class also needs: extends SpringBootServletInitializer, and a method:
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
     return application.sources(VideoConverterWebApplication.class);

After these updates, the mvn package command should produce a .war file that will most likely deploy successfully onto your web container.

Leave a Reply

Your email address will not be published. Required fields are marked *