Using MAVEN to automatically deploy Java Web projects to tomcat issues

Source: Internet
Author: User
Tags response code stack trace java web pscp tomcat server

Guide

First of all, why do you use MAVEN to manage projects, a direct reason is: I developed a Web project on my own computer, every time I deploy to the server, I have to go through the following steps:

    1. First package the project into a war package in eclipse
    2. Delete the original project folder on the server
      cd /var/lib/tomcat7/webappssudo rm XXX.warsudo rm -rf XXX
    3. Upload the war package to the server, such as with the PSCP command
      pscp -pw "xxx" XXX.war [email protected]:/var/lib/tomcat7/webapps
    4. Restart Tomcat
      sudo service tomcat7 restart

Each of these steps, very annoying, and using MAVEN to manage it does not require these steps, directly in Eclipse configuration maven plug-in, and then use MAVEN from the deployment project, about how automatic deployment can be a lot of online tutorials, specific to the following reference, Once the deployment is successful, only one command is required to automatically deploy my Web project to the Tomcat server, and I typically use the following command:

mvn tomcat7:deploy -Dmaven.test.skip=true

Where-dmaven.test.skip=true means to temporarily skip the compilation of the Test code (also available-dskiptests to skip the test phase), Maven.test.skip also controls the behavior of the Maven-compiler-plugin and maven-surefire-plugin two plug-ins, skipping compilation and skipping tests.

But for the first time to follow the tutorial always encounter a variety of problems, the following records I encountered in the deployment process of various issues and considerations, to provide reference significance.

MAVEN Usage Issues note
  1. The Tomcat plugin in Maven config file Pom.xml is typically configured as follows:

    <plugin>  <groupId>org.codehaus.mojo</groupId>  <artifactId>tomcat-maven-plugin</artifactId>  <version>1.1</version>  <configuration>     <path>/test</path>     <url>http://localhost:8080/manager/</url>     <server>tomcat</server>  </configuration></plugin>

    The server inside needs to be configured in Maven config file settings.xml as follows:

    <server>  <id>tomcat</id>  <username>admin</username>  <password>123456</password></server>

    The username and password here are typically the user name and password for the Tomcat server.

  2. When you

    Start running the automatic deployment command, you must first start Tomcat. Otherwise, the following error is reported:

    [INFO] [INFO]---tomcat-maven-plugin:1.0:redeploy (default-cli) @ sshmj-frank---[INFO] deploying war to http://localhost:8080 /sshmj-frank [INFO]------------------------------------------------------------------------[INFO] BUILD FAILURE [I NFO]------------------------------------------------------------------------[INFO] Total time:9.630s [INFO] Finished At:tue 16:35:52 CST [INFO] Final memory:6m/15m [INFO]------------------------------------------- -----------------------------[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.0:redeploy ( DEFAULT-CLI) on Project Sshmj-frank:cannot invoke Tomcat manager:connection refused:connect, [Help 1] [ERROR] [  ERROR] To see the full stack trace of the errors, re-run Maven with THE-E switch. [ERROR]  Re-run Maven using The-x switch to enable full debug logging.   [ERROR] [ERROR] For more information on the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 
  3. HTTP 403 error

      [ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat-maven-plugin:1.1: Deploy (DEFAULT-CLI) on Project Xxx:cannot invoke Tomcat Manager:server returned HTTP response code:403 for url:http:/ /localhost:8080/manager/html/deploy?path=xxx, [Help 1]  

    Online Some people say that there are two possible reasons for this problem:
    1) If you are using Tomcat 7, you need to modify the URL address of the deployment in Pom.xml, change
    <url>http://localhost:8080/manager</url>
    to
    <url>http:// Localhost:8080/manager/text</url>
    2) The Tomcat User Rights assignment issue requires both Manager-gui and Manager-script permissions. For example, forget to assign Manager-script permissions. The
    correct conf/tomcat-users.xml configuration should be:

      <tomcat-users> <role rolename= "Manager-gui"/> <role rolename= "Manager-script"/> < User username= "admin" password= "admin" roles= "Manager-gui, Manager-script"/></TOMCAT-USERS>  

    But my problem is not the above two, my problem is that the automatic deployment command is wrong, should be the MVN tomcat7:deploy command, and I used to be mvn tomcat:deploy command

  4. "Application already exists at path" issue
    when deployed to a tomcat server using the Tomcat7-maven-plugin plug-in, items that already have the same name on the server cause

      fail-application already exists at path ...  
    The

    Workaround is to add the parameter update

    when you configure the Tomcat7-maven-plugin plug-in in the Pom.xml file
      <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId> tomcat7-maven-plugin</artifactid> <version>2.0-SNAPSHOT</version> <configuration> <url >http://XXX:8080/manager/html</url> <server>tomcat</server> <username>admin</usern ame> <password>12345</password> <path>/${finalName}</path> <update>true< ;/update> </configuration></plugin>  
  5. "Web. XML which'll be ignored" issue
    When you compile a project with Maven, it appears:

    [WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as ‘true‘)

    The workaround is to add one of the following plugin:

    <plugin>  <groupId>org.apache.maven.plugins</groupId>  <artifactId>maven-war-plugin</artifactId>  <version>2.1.1</version>  <configuration>     <packagingExcludes>WEB-INF/web.xml</packagingExcludes>  </configuration></plugin>
Resources
    • Automatically deploy Java Web Apps to the Tomcat server using MAVEN
    • Maven Getting Started example (3): Automatically deployed to external Tomcat
    • Maven Getting Started example (4): Automatically deploy Tomcat error exclusions
    • FAQ in MAVEN Usage

Excerpt from: http://blog.csdn.net/lanxuezaipiao/article/details/40356991

Using MAVEN to automatically deploy Java Web projects to tomcat issues

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.