简体   繁体   中英

Deploy maven project to tomcat

I have Maven project and Tomcat server. I work in IDEA when I click in "Maven LifeCicle" -> "deploy", i have a problem:

[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ TestMaven ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.035 s
[INFO] Finished at: 2014-09-20T13:52:32+04:00
[INFO] Final Memory: 11M/93M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project TestMaven: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [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 about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Piace of my POM.xml is:

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

Not worked or:

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.0</version>
        </plugin>

also not worked.

In the default maven lifecycle mvn deploy means to deploy one or more build artifacts to a maven repository. The reason is because the maven-deploy-plugin 's deploy goal is bound to the deploy phase of the lifecycle. This configuration is automatically done when you use for example packaging jar .

In maven

  • a maven build lifecycle is made up of phases
  • a phase is made up of plugin goals
  • the packaging type (eg jar, ear, war) pre-configures plugins goals for execution in a lifecycle phase

In order to solve your problem I would first package the webapp and then invoke the deploy goal of the tomcat7-maven-plugin .

mvn package org.apache.tomcat.maven:tomcat7-maven-plugin:2.0:deploy

or simply

mvn package tomcat7:deploy

The mvn command above means:

  • invoke the default build lifecycle until phase package
  • then the goal deploy of the tomcat7 plugin.

If you want to know how maven resolves tomcat7:deploy to org.apache.tomcat.maven:tomcat7-maven-plugin:2.0:deploy you should read more about plugin groups and plugin naming conventions.

With maven deploy command, usually gets errors for various reasons. if you work in Unix/Linux system, I recommend using "rsync" method on console. (You can write own shell script to manage easily). It helps not only deploying without a problem but also helps to get time while redeploying (only uploading changed / new files). Because maven deploy / redeploy uploads your project as a bundle in jar/war. However "rysnc" method uploads your project files one by one.

Before using it, you should sure that two conditions.

1- your project is built in target folder (Spring Tool Suite)

2- you have access to tomcat via ssh

example code : (v_ : prefix which is variable(customizable))

rsync -avz v_your_project_in_target root@v_ip:v_tomcat_name/webapps/v_project_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM