Maven web项目通过插件实现热部署到Tomcat

学习Maven配置热部署,学习别人的经验,做个备忘录,希望可以帮到您

配置Tomcat热部署权限

打开tomcat目录/conf/tomcat-users.xml 


文件底部权限配置


启动tomcat


进入manager管理页面   URL:http://ip:端口/manager,输入(1)中设置的用户名、密码,进入后如下图:


登录成功



maven配置

修改项目的pom.xml文件,在<build>节点下面增加如下配置:
 <!-- 编译相关插件,1.8是jdk版本 -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.5.1</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
          </configuration>
        </plugin>
        <!--tomcat插件 -->
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.1</version>
          <configuration>
            <!-- tomcat地址,manager/text该地址可追加命令 -->
            <!--http://localhost:8080/manager/stop?path=/ //停止 -->                                                                                <!--http://localhost:8080/manager/start?path=/ //启动 -->
            <!--http://localhost:8080/manager/text/deploy?path=/ //部署 -->
            <!--http://localhost:8080/manager/text/undeploy?path=/ //卸载 -->
            <url>http://localhost:8080/manager/text</url><!-- 远程服务器url地址 -->
            <username>admin</username>
            <password>admin</password>
            <!-- 此处的名字是项目发布的工程名 -->
            <!-- <path>/rspsm-dp-plus-console</path> -->
          </configuration>
        </plugin>
        <!-- 忽略项目中测试错误,在发布过程中会运行项目中的测试代码 -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <testFailureIgnore>true</testFailureIgnore>
          </configuration>
        </plugin>
        <!-- war插件 -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.0.0</version>
          <configuration>
            <webResources>
              <resource>
                <!-- WEB-INF文件地址,idea是web,eclipse是webRoot -->
                <directory>\src\main\webapp</directory>
              </resource>
            </webResources>
          </configuration>
        </plugin>

打开DOC窗口,进入项目所在的目录 运行部署命令mvn tomcat7:deploy


部署成功


刷新manager管理页面,我们已经可以看到部署到tomcat的项目


Hello World!

如以上配置不能完成运行,请联系我!

如有错误,敬请包含,请帮忙指出,大家一起共勉!不胜感激




猜你喜欢

转载自blog.csdn.net/qq_28538075/article/details/80298659