Sunday, April 27, 2014

Maven 3.1.1 Tomcat 7 Plugin deploy

I ever understood the official documentations, if they where based on examples instead of full of generic crap, it may be 1000 time more useful.

Anyway, after some time googleing this is my configuration for the Apache Tomcat Maven Plugin for Tomcat 7.x and Maven 3.x.


1. Into pom.xml in the build/plugins tag add:

<plugin>
   <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
       <server>tomcatserver</server>
       <url>http://localhost:8080/manager/text</
       <path>/</path>
       <username>admin</username>
       <password>admin</password>
   </configuration>
</plugin>


2. The server name "tomcatserver" needs to match with the server declared into the maven settings.xml. You can use the one in maven home or userhome/.m2 folder.

In linux you can check where is your maven with the command "which mvn". In ubuntu is in "/usr/local/apache-maven/apache-maven-3.1.1".

Edit the conf/settings.xml and add the follow snippet into the "servers" tag:

<server>
   <id>tomcatserver</id>
   <username>admin</username>
   <password>admin</password>
</server>

Note: edit the password as you wish.


3. Edit the "tomcat-users.xml" in the "tomcat.home/conf" and add the admin user as follows inside of the "tomcat-users" tag:

<user username="admin" password="admin" roles="manager-script"/>

Note: The "tomcat.home" depends how you installed tomcat, if you installed through apt-get the config files usually are under "'/etc/tomcat6/7".


4. Run the plugin as follows:

"mvn package tomcat7:run" For deploying and running tomcat in the same terminal use.

"mvn package tomcat7:deploy" If you have tomcat 7 already up and running just use this command in order to deploy the war file. The pom.xml needs to be properly configured to produce a war file, see maven documentation for more details.

"mvn package tomcat7:redeploy" to redeploy the application.


That is all, I hope it helps
Keep coding !


Posted by Marc Andreu Fernandez.

No comments: