Conventionally, a Servlet Maven project is deployed to Tomcat production server by deploying a generated war to the - webapps - directory of Tomcat. However, Spring-Boot, as a practical trend, recommends jar
over war
. This preference has no problem for testing, but in case of deployment to an existing Tomcat server in Production, AFAIK, only a war is accepted. So my solution would be:
- Generate a corresponding war by modifying the Maven's pom.xml, i.e. set the value of
packaging
element aswar
as such:<packaging>war</packaging>
. But this is manifestly an extra step - Deploy the project in Production as a running Java program with the embedded Tomcat, meaning there is no normal Tomcat Server at all in production. But is the embedded Tomcat as stable in production as the normal Tomcat server?
- In case of deploying a Spring MVC project (no Spring Boot!) to an existing Tomcat server, I tried to use Tomcat Maven plugin in the testing phase instead of using Eclipse with Tomcat server configuration as the Tomcat server should be installed locally as a prerequisite.
Question: Are the solutions above OK? or are there any other better solutions of deployment to production? In case of the third solution, there is only Tomcat7 Maven plugin according to my knowledge, what if I only want to test with Tomcat 8 or Tomcat 9? I tried to use a main class to start up an embedded Tomcat, but it is superb difficult to deal with the dependencies.