Make war with with embedded tomcat

160 Views Asked by At

I have recently created a web application using spring mvc, gradle and tomcat to host it. I have been trying to create a war file of the web application which can be executed on its own with no need to have gradle and tomcat installed on your computer.

For example running java -jar <path-to-war> and the server will be running on the localhost port specified.

What is the best way to approach this?

1

There are 1 best solutions below

0
On

use spring boot, comes with embedded tomcat,include below in pom and

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
</dependency>

Main method

@SpringBootApplication
public class AppApplication {

public static void main(String[] args) {
    SpringApplication.run(AppApplication.class, args);
}
}