源:

评:

maven常用插件之tomcat
插件作用:在maven项目中,使用tomcat6、tomcat7运行maven项目。

1.声明repository及pluginRepository


<          repositories          >         


                    <          repository          >         


                    <          id          >people.apache.snapshots</          id          >         


                    <          url          >http://repository.apache.org/content/groups/snapshots-group/</          url          >         


                    <          releases          >         


                    <          enabled          >false</          enabled          >         


                    </          releases          >         


                    <          snapshots          >         


                    <          enabled          >true</          enabled          >         


                    </          snapshots          >         


                    </          repository          >         


                    </          repositories          >         


                    


                    <          pluginRepositories          >         


                    <          pluginRepository          >         


                    <          id          >apache.snapshots</          id          >         


                    <          name          >Apache Snapshots</          name          >         


                    <          url          >http://repository.apache.org/content/groups/snapshots-group/</          url          >         


                    <          releases          >         


                    <          enabled          >false</          enabled          >         


                    </          releases          >         


                    <          snapshots          >         


                    <          enabled          >true</          enabled          >         


                    </          snapshots          >         


                    </          pluginRepository          >         


                    </          pluginRepositories          >



2.添加tomcat6、tomcat7插件


<          plugins          >         


                    ...         


                    <          plugin          >         


                    <          groupId          >org.apache.tomcat.maven</          groupId          >         


                    <          artifactId          >tomcat6-maven-plugin</          artifactId          >         


                    <          version          >2.0-SNAPSHOT</          version          >         


                    <          configuration          >         


                    <!--         


                    默认访问路径为:http://localhost:8080/${project.name}         


                    下面指定访问路径为: http://localhost:8080         


                    -->         


                    <          path          >/</          path          >         


                    </          configuration          >         


                    </          plugin          >         


                    <          plugin          >         


                    <          groupId          >org.apache.tomcat.maven</          groupId          >         


                    <          artifactId          >tomcat7-maven-plugin</          artifactId          >         


                    <          version          >2.0-SNAPSHOT</          version          >         


                    <          configuration          >         


                    <          path          >/</          path          >         


                    </          configuration          >         


                    </          plugin          >         


                    ...         


                    </plugins



3.在settings.xml文件里添加groupId


<          pluginGroups          >         


                    ....         


                    <          pluginGroup          >org.apache.tomcat.maven</          pluginGroup          >         


                    ....         


          </          pluginGroups          >



最后执行下面命令,就可以在tomcat里运行maven项目了



mvn tomcat6:run



mvn tomcat7:run