1. Configure a tomcat user.
Open the <tomcat>/conf/tomcat-users.xml file and enter the following. If there are already tomcat users defined in the xml file then just add the new role and user to the list.
<tomcat-users> <role rolename="manager"/> <role rolename="admin"/> <user username="admin" password="admin" roles="admin,manager"/> </tomcat-users>
Now we can access the tomcat manager (http://localhost:8080 and click “Tomcat Manager”) with username admin and password admin.
We also now have the permission to deploy applications to Tomcat.
2. Configure maven to be able to login to the tomcat manager application.
Open <maven>/conf/settings.xml and enter the following to the <servers> list:
<server> <id>mytomcatserver</id> <username>admin</username> <password>admin</password> </server>
3. Modify the pom.xml file to include the tomcat-maven-plugin.
In Eclipse, open the pom.xml file and replace the existing <build> with the following:
<build> <finalName>SpringGreetings</finalName> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <server>mytomcatserver</server> <path>/springgreetings</path> <url>http://localhost:8080/manager</url> <username>admin</username> <password>admin</password> </configuration> </plugin> </plugins> </build>
What is this plugin? Maven will download this plugin code now, if you don’t already have it in your local repository. This plugin will compile and deploy the application to tomcat. You don’t need to do anything else!
4. Deploy the application to tomcat.
Assuming tomcat is already up and running (it needs to be running in order to deploy!) enter the following in TERMINAL:
$ cd SpringGreetings $ mvn tomcat:deploy
Now you can open a web browser with the url http://localhost:8080/springgreetings/
You can also see the application deployed in the <tomcat>/webapps folder. There should be a folder inside the webapps directory called “springgreetings” and another file called “springgreetings.war”
5. Make a change in Eclipse, redeploy.
Open the file index.jsp in Eclipse and change “Hello World!” to “Welcome to Spring Greetings!” and then redeploy in TERMINAL:
$ mvn tomcat:redeploy