no

Learn to Deploy a Javaee War in Tomcat 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...

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

Related

javaee 3468693129987180999

Post a Comment Default Comments

1 comment

ramasrinu said...

[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.0-SNAPSHOT:deploy (default-cli) on project rest-sample: Cannot invoke Tomcat manager: http://localhost:8085/manager/html/deploy?path=%2Frest-sample -> [Help 1]

item