How To Package OpenLegacy API Project as WAR

How To Package OpenLegacy API Project as WAR

Step-by-Step Guide


Prerequisite:
 A jar file from your SDK project.


Packaging our API project as a WAR and deploying on a Tomcat server is easily done by following these steps:

  1. Extend the existing api-project/ProjectApplication class with SpringBootServletInitializer and override the configuration method:

    @SpringBootApplication
    public class ProjectNameApplication extends SpringBootServletInitializer {
    
       // override configure method    
       @Override
       protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
       return builder.sources(ProjectNameApplication.class);
       }
    
       public static void main(String[] args) {
       SpringApplication.run(ProjectNameApplication.class, args);
       }
    
    }
  2. Add springfox-swagger-ui dependency to the  pom.xml file:

     <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${springfox.version}</version>
            </dependency>
  3. Update packaging to war in pom.xml file:

    <packaging>war</packaging>
  4. Exclude tomcat-embed from the pom.xml

            <!-- Spring -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>${spring-boot.version}</version>
                <exclusions>
                   <exclusion>
                       <groupId>org.apache.tomcat.embed</groupId>
                       <artifactId>tomcat-embed-websocket</artifactId>
                   </exclusion>
                </exclusions>
            </dependency> 
  5. Remove src/main/java/com/ts_api_war/openlegacy/config/WebMvcConfiguration.java class. 

  6. Remove the authentication from the API pom XML. 

  7. Build the project - How To Build A Project In IDE

  8. The WAR file will be created in your project's target folder.

After deploying the war file it will present on http://localhost:8080/{{project-name}}/swagger-ui.html


For more Tomcat information please review:

https://tomcat.apache.org/tomcat-9.0-doc/appdev/index.html

https://www.baeldung.com/tomcat-deploy-war

Filter by label

There are no items with the selected labels at this time.