If you want to develop web applications and Apache Tomcat is your target web server, you need to know how to deploy WAR files to Tomcat so you can see if your applications function at runtime.
Here are five different ways to deploy WAR files to Tomcat.
1. Just copy and paste
Perhaps the simplest way to deploy a WAR file to Tomcat is to copy the file to Tomcat’s webapps directory. Tomcat monitors this webapps directory for changes, and if it finds a new file there, it will attempt to deploy it. So if you do your application build on the same machine as your Tomcat server, a deployment is a simple as performing a cut and paste.
Perhaps the simplest way to deploy a WAR file to Tomcat is to copy the file to Tomcat’s webapps directory. Tomcat monitors this webapps directory for changes, and if it finds a new file there, it will attempt to deploy it. If you do your application build on the same machine as your Tomcat server, simply cut and paste it to begin deployment.
2. FTP your WAR files
If your Java web server is installed on a remote machine, a simple copy and paste won’t work. Instead, you need to perform the network equivalent, a FTP to the remote server. The deployment target remains the same, which is the webapps folder of the remote Apache Tomcat server.
3. Deploy with your IDE
Any popular IDE that supports Java-based development — including Eclipse, NetBeans and IntelliJ — integrates their web development tools with Apache Tomcat, which allows you to deploy with just a mouse click or two. In Eclipse, all you need to do is right-click on any Servlet, JSP or web project and select Run As –> Run on Server, and a WAR file deployment to Tomcat will occur.
4. Deploy WAR files with Maven
If you use Maven as your build tool, you can add deployment features by editing the POM file and specifying the URL and the credentials required to connect and deploy to Tomcat. With the correct POM file configurations made, running the Maven deploy command will result in a complete build, and the packaged web application will be deployed as a WAR file to Tomcat.
5. Deploy WAR files with Jenkins
Many organizations have embraced the concept of continuous delivery, and a key part of that is the ability to use Jenkins as their continuous deployment tool. There are several Jenkins add-ons available to deploy a WAR file after a CI pipeline successfully runs. One of the most popular ones is the Deploy to Container plugin. Once this plugin is configured, any Jenkins build job can deploy a WAR to Tomcat with the addition of the “Deploy WAR/EAR to a Container” post-build action to the Jenkins job.
The nice thing about Tomcat is its flexibility on how it performs a deployment. There are a variety of different ways to deploy WAR files to Tomcat, be it as simple as a copy and paste, or as involved as the execution of a CI pipeline with Jenkins.