Maven tomcat plugin: tomcat7: run or tomcat7: run-war?

I am using tomcat7-maven-plugin

in my Java web application. Now I can start my web server using the command mvn clean tomcat7:run

. I recently noticed that there is another command tomcat7:run-war

from https://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/plugin-info.html which reads:

tomcat7: Startup:
Runs the current project as a dynamic web application using the embedded Tomcat server.

tomcat7: run wars:
Runs the current project as a packaged web application using the built-in Tomcat server.

I know the command tomcat7:run-war

will package my application into a file jar

or war

and then run it on an embedded server. My question is, under what circumstances should we use this command, is tomcat7:run

n't it enough? Or maybe running a packaged application will have better performance? I'm not sure. Thank you in advance.

+7


source to share


1 answer


Short answer

The performance of the running application and the server is the same. However, you usually want to use run-war

it because it gives you the added benefit of delivering military files. You want to use run

it if you absolutely need your application to run locally as quickly as possible (hardly ever).


Here are the details

Let's start by explaining what a war file is and why it's created:

WAR. File extension that packages a web application a directory hierarchy in ZIP format and is short for web archive. Java web applications are usually packaged as WAR files for deployment. [Baeldung]

Why are Java web applications packaged as WAR?

Because a WAR is not only a zip file, but (well-formed) enforces the specifications of a Java web application. You can deploy and run the war file in any container. Checkout Wikipedia for more benefits.

Different goals, different results

Targets tomcat:run

and tomcat:run-war

runs your application on the embedded Tomcat server. tomcat:run-war

includes an additional target package

to package your application into a WAR file. This WAR file will then be unpacked by the embedded Tomcat server so that the application can run. Thus, the application and the server are the same, but the result is run-war

different, because you get an additional WAR file.

But why is this WAR file useful?



First of all, there is no downside to this, except for an increase in build time by a few seconds. Even hot swap tools and functions work with a WAR file in between. The main reasons for creating a WAR file for this purpose are:

  • Testing
  • Multiple deployments
  • CI conveyor
  • Archiving

Testing. Building the WAR file means that your build pipeline goes through all the stages of building a WAR. Later you will deploy this WAR file (reminder: this is the standard for containers) and you can verify that the "build", "unpackage" and "deploy" steps are working correctly. Alternatively, you can check the file structure if it is not.

Multiple deployments . You can build and run the application locally, but you can still deploy this WAR file to more than one container that you are running. There are industry scenarios where you need to make sure your WAR file is running in different containers and you can use that file to deploy it anywhere.

CI pipelines . Not only may you want to use the application locally, but you may want to integrate the result into your continuous integration. You might even automatically deploy a local build to a test server, but it's more likely that you have an automated process on the CI server that creates the WAR, runs it on some test or staging system, and then forwards the WAR if that works correctly ...

Archiving . You might want to keep all WAR files from the previous build. Maybe for one of the reasons mentioned, or just as a backup for quick historical access. It might also be interesting to see how disk space and memory usage change as the application grows. Archiving WAR files is a way to investigate this. They can also be deployed to a WAR archive server.


Conclusion

Both targets have their uses, but it is usually preferable to use a target run-war

because of the benefits you get by additionally creating a WAR file.

Denial of responsibility

Since this topic is a little outdated, I might add the following: I'm just doing a historical overview. Use cases and needs may differ today for each individual use case. Some processes, maven targets and plugins are deprecated or there are best practices. I am just explaining the possible intentions behind this goal during its development.

0


source







All Articles