How to deploy a .WAR file in Tomcat using Eclipse [ 2024 ]
How do you deploy a WAR file in Tomcat using Eclipse?
This post will teach you how to use Eclipse to deploy a sample WAR file in Tomcat. First, we will create a Java web project and then deploy it on the Tomcat server.
A .war (Web Application Archive) file is a packaged file format used to distribute Java-based web applications, containing servlets, JSP files, HTML, and other resources needed to run the application on a server like Apache Tomcat. It simplifies deployment by bundling all components into a single archive.
Tomcat Install
Steps to install the Tomcat server on the Windows operating system:
Adding Tomcat Runtime in Eclipse IDE
Java Web Project
You can create a web project by navigating File >> New >> Other… >> Web >> Dynamic Web Project
Give the Project name of your choice, for example, MyWebProject, and click on the Next button. You can select the target runtime to optimize the application for a specific server. Choose the Apache Tomcat server runtime.
Choose the context root and content directory as MyWebProject and WebContent, respectively. Select the “Generate web.xml deployment descriptor option as shown in the picture. This option will create a deployment descriptor for the project.
Create a Servlet
Create a servlet and add it to the project. We can also create .html files or .jsp files etc. for the project.
Start the Tomcat server.
Deploying a.WAR file
Right-click on the web project and click Export >> War File menu option.
Choose the WAR file export settings to deploy the .war file in Tomcat. Select the web project, destination folder, target runtime, and other options, and click the Finish button.
After completing the step, verify the web apps folder of the Tomcat server. The war file would be deployed.
Browse the servlet URL mapping under the project context to verify that your application is running.
Screenshot
That’s it, you have successfully deployed your application on the Tomcat server. For manual deployment, deploying or re-deploying war files is automatic. You can copy/overwrite the .war file, check your web apps folder for an extracted folder.
More information on tomcat deployment at:
- https://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.html
You can replace the version number in the above URL for more version-specific instructions on Tomcat deployment.