In this article, we will use Maven-Tomcat plugin to deploy a WAR file to Tomcat 7. We will use A sample Spring-based application PetClinic available at https://github.com/spring-projects/spring-petclinic
Download the application and extract the files.
Install Maven 3, Download Tomcat 7 from https://tomcat.apache.org/download-70.cgi
Now go to apache-tomcat-7.0.68\conf\tomcat-users.xml
First, add an admin user with roles "manager-gui" and "manager-script".
<user username="admin" password="password" roles="manager-gui,manager-script" />
Now, let's add Tomcat's admin user that we created in the Maven setting file.
<!-- Another sample, using keys to authenticate.
<passphrase>optional; leave empty if not used.</passphrase>
Now the remaining thing is to declare a Maven-Tomcat Plugin in pom.xml. We are using sample Spring-based application PetClinic available at https://github.com/spring-projects/spring-petclinic. It already has that configuration but we need to change.
Locate Tomcat Plugin block in Pom.xml (https://github.com/spring-projects/spring-petclinic/blob/master/pom.xml). In my case, I changed port number to 8080.
Make sure that Server Name (tomcat-development-server) is same that we provided in settings.xml of Maven as Id.
When we execute mvn tomcat7:deploy command, Maven deploy the WAR file to Tomcat 7 using Manager App “http://localhost:8080/manager/text” , on path “/petclinic“, using “tomcat-development-server” (in settings.xml of Maven) and username and password for basic authentication.
Before using mvn tomcat7:deploy, visit http://localhost:8080/
Click on Manager App; it will ask for Username and Password. Give username and password configured in the tomcat-users.xml.
Once you are authenticated properly, execute mvn tomcat7:deploy
If you face proxy related issues while executing mvn command then visit- Solved: How to enable proxy setting in Maven to Download Jar files
Now Verify deployed application at http://localhost:8080/petclinic/
Labels: Apache Maven, Java, Spring, Tomcat