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:
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); } }
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>
Update packaging to war in pom.xml file:
<packaging>war</packaging>
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>
Remove
src/main/java/com/ts_api_war/openlegacy/config/WebMvcConfiguration.java
class.Remove the authentication from the API pom XML.
Build the project - How To Build A Project In IDE
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
Related articles
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.