Deploy a javaee6 war in tomcat7 using maven
Tech-Today

Deploy a javaee6 war in tomcat7 using maven


Recently, I'm trying to deploy a simple web application (war) in tomcat7 but it seems the old maven way of deploying a war will not work on it.

The plugin I used to use for tomcat6 is:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://127.0.0.1:8080/manager</url>
<server>MyServer</server>
<path>/myApp</path>
</configuration>
</plugin>
But it doesn't work for tomcat7 server. After googling, I found a new plugin for deploying in tomcat7: http://tomcat.apache.org/maven-plugin-2.0-SNAPSHOT/snapshot-test.html And so here's how I use the new plugin: 1.) Add the ff lines in your maven's settings.xml, usually found in %user%/.m2 folder.
<server>
<id>TomcatServer</id>
<username>admin</username>
<password>admin</password>
</server>
2.) Modify tomcat's 7 tomcat-users.xml file, which can be found inside "%tomcat_installation%/config, and add the ff lines:
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
Take note that manager roles has been broken down into 4 roles as you can see. 3.) In your pom.xml file, add these repository and plugin repository:
<repositories>
<repository>
<id>people.apache.snapshots</id>
<url>http://repository.apache.org/content/groups/snapshots-group/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Apache Snapshots</name>
<url>http://repository.apache.org/content/groups/snapshots-group/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
4.) Then, what I usually does is to create a development profile where I can set the deployment mechanism in my local machine, in this case using the tomcat7 maven plugin:
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
<configuration>
<url>http://localhost:8080/manager/html</url>
<server>TomcatServer</server>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Note that the url needs the additional /html, as it's updated by apache, otherwise you will get the error: "403 access denied" 5.) You can now invoke the tomcat7 deploy command as documented by the link in the top of this writing.
mvn tomcat7:deploy




- How To Package A Java Standalone App Using Maven Assembly
The sample codes below will assemble a zipped package of a java standalone app. Dependencies: maven-jar-plugin - to create the jarmaven-assembly-plugin - to assemble the distribution packagepom.xml<plugin> <groupId>org.apache.maven.plugins</groupId>...

- How To Get Git Build Id Using Maven
There are times when git's build number is important for a release. Specially in development mode, when there are frequent releases. So if we want to append the build number on our page, how do we automate it? For us to achieve this we will need 2...

- Deploy A J2ee Ear In Glassfish Using Maven
The ff code will explain how a j2ee ear project can be deploy by invoking a maven goal. The plugin: http://maven-glassfish-plugin.java.net/deploy-mojo.html To deploy to a glassfish server using maven, invoke (inside your ear project): mvn glassfish:deploy...

- How To Setup Findbugs With Maven On Eclipse
Before you proceed with this exercise, it's required to check my blog on how to create a modular maven project. http://czetsuya-tech.blogspot.com/2012/04/how-to-create-modularized-maven-project.html 1.) In this link you will...

- How To Add Pmd Reporting To Maven
Before proceeding to this exercise, you may want to try my tutorial on how to setup a maven project to eclipse: http://czetsuya-tech.blogspot.com/2012/04/how-to-create-modularized-maven-project.html. Assuming you have follow the tutorial above, you should...



Tech-Today








.