Friday 29 July 2022

How to deploy a war file to tomcat?

In this post, I am going to explain how to deploy a war file to Apache tomcat.

 

Prerequisite

Setup maven

Setup Java

 

This tutorial is devided into two sections.

a.   Create a war file

b.   Deploy the war file to tomcat.

 

Step 1: Create a war file.

 

Open terminal and execute below command to generate a sample Maven webapp project.

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=1.4

 

Above command generate the project in interactive mode. Provide below details.

a.   Version as 1

b.   Package as com.sample.app

c.    groupId as com.sample.app

d.   artifactId as helloworld

 

Upon successful completion of the above command, a webapp project template is created.

 

Project structure looks like below.

$tree helloworld/
|____
| |____pom.xml
| |____src
| | |____main
| | | |____webapp
| | | | |____index.jsp
| | | | |____WEB-INF
| | | | | |____web.xml

 

Navigate to the folder helloworld and execute the command ‘mvn clean install’ to generate a war file. Generated war file location is helloworld/target/helloworld.war.

 

Step 2: Deploy the war file to tomcat. You can find the instructions to setup tomcat here.

 

Start the tomcat server. Open the url ‘http://localhost:8080/’ in browser.

 


Click on Manager App button. It prompts you for the login details.

 

 


Enter username and password that you configured, click on Sign In button. You will be taken to ‘Tomcat Web Application Manager’ page.

 

Navigate to 'WAR file to deploy' section in Tomcat Web Application Manager page.




Browse the war file, and click on Deploy button.

 

Once deployment is successful, you can see helloworld application is available in Applications section.

 


 

Click on the hyperlink helloworld, to open the helloworld application.

 


 

That’s it, you are done…


  

Previous                                                 Next                                                 Home

No comments:

Post a Comment