Using MAVEN to automatically deploy Java Web projects to tomcat issues

Source: Internet
Author: User
Tags response code stack trace 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 uploading
    PSCP-PW "xxx" Xxx.war [Email protected]:/var/lib/tomcat7/webapps  
  4. restart Tomcat
    sudo Service tomcat7 Restart  

Every time these steps, very annoying, and using MAVEN to manage it does not need these steps, directly in Eclipse configuration maven plug-in, and then use MAVEN from the deployment project, about how to automatically deploy a lot of online tutorials, see the following reference material, 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, be sure to start Tomcat first. 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]

    Some people on the internet say 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.
    <url>http://localhost:8080/manager</url>
    Switch
    <url>http://localhost:8080/manager/text</url>
    2) Tomcat User Rights assignment problem, need to have both Manager-gui and Manager-script permissions, such as 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 the automatic deployment command is wrong, should be mvn tomcat7:deploy command, and I used to mvn tomcat:deploy command

  4. "Application already exists at path" issue
    When deployed to a tomcat server using the Tomcat7-maven-plugin plug-in, projects 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 configuring the Tomcat7-maven-plugin plugin 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</username> <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 would be ignored (Webxml attribute was missing from WA R 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

Using MAVEN to automatically deploy Java Web projects to tomcat issues

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.