maven拓展——使用tomcat插件运行maven项目

首先,在pom.xml中配置插件:

<build>  
    <plugins> 
              <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <port>8080</port>
                    <path>/ssm-crud</path>
                    <uriEncoding>UTF-8</uriEncoding>
                    <finalName>ssm-crud</finalName>
                    <server>tomcat7</server>
                </configuration>
            </plugin>
    </plugins>  
  </build>  

在eclipse中配置maven插件(见另外一篇博客):

  选择pom.xml文件——>右键——>选择 Run As——> Maven build ...

    几个常用的maven命令:

命令 描述
tomcat:deploy 部署一个web war包
tomcat:reload 重新加载web war包

tomcat:start

启动tomcat

tomcat:stop

停止tomcat

tomcat:undeploy

停止一个war包
tomcat:run 启动嵌入式tomcat ,并运行当前项目

    在这里要注意一下,该插件命名方式有些不同,比如启动tomcat ,对应的目标命令是: tomcat7:run ,同样,其它命令也是这样,需要更改为:tomcat7:<插件执行点>

    

  //maven在网络不稳定时会产生一些奇怪的问题,解决方案是删掉重新下载!

     【更新】:eclipse中的tomcat是一个服务器的镜像,我们可以使用Maven的 maven install,进行打包,可以在 target目录下生成打包好的war包,这便是maven的构建功能。将war包直接复制到真正tomcat的webapps目录下即可运行,运行的路径即为文件名称!

原文地址:https://www.cnblogs.com/jiangbei/p/7082868.html