首页 > 代码库 > maven自动化:部署项目到tomcat

maven自动化:部署项目到tomcat

1. tomcat中配置用户

tomcat_home/conf/tomcat-users.xml配置文件中,添加如下信息:

|-- tomcat-users.xml

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 

  <role rolename="manager-gui"/>
  <user username="admin" password="admin" roles="manager-gui"/> 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

2. settings.xml中配置tomcat服务器信息

在maven_home/conf/settings.xml配置文件中,添加如下信息

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


<servers>

  ……

 <!-- 配置部署项目的tomcat服务器 -->
 <server>
      <id>myserver</id>
      <username>admin</username>
      <password>admin</password>
    </server>

……

</servers>


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


3. 项目的pom.xml中配置发布信息

在项目管理配置文件中添加项目发布信息

|-- 需要注意,tomcat在这里做了一些更新,网上大部分的教程和信息,在这里有不同的问题。请大家参考如下:

tomcat官网提示:

Since version 2.0-beta-1 tomcat mojos has been renamed to tomcat6 and tomcat7 with the same goals.

You must configure your pom to use this new groupId:

以前的tomcat发布插件,从2.0-beta-1版本开始,tomcat mojos被替换成tomcat6/tomcat7了,以后在你的项目中必须按照以下的方式进行配置

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


<pluginManagement>
      <plugins>

        <!-- 配置tocmat6插件 -->
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat6-maven-plugin</artifactId>
          <version>2.3-SNAPSHOT</version>
        </plugin>
<!-- 配置tocmat7插件 -->
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.3-SNAPSHOT</version>
        </plugin>
      </plugins>
    </pluginManagement>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

或者,直接在maven_home/conf/settings.xml中配置如下信息即可

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


4. maven中发布项目

tomcat在更新了配置之后,发布项目的一些命令也相应的做了调整

|-- 发布项目

|-- 卸载项目

|-- 启动项目

|-- 停止项目

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Redeploying a WAR project【发布项目】

The goals required to redeploy a WAR project depend upon how it was deployed:

  • To redeploy a WAR project deployed by tomcat:deploy you can type:使用tomcat6/7:deploy发布项目 
    mvn package tomcat6/7:redeploy
  • To redeploy a WAR project deployed by tomcat:exploded you can type:
    mvn war:exploded tomcat6/7:redeploy
  • To redeploy a WAR project deployed by tomcat:inplace you can type:
    mvn war:inplace tomcat6/7:redeploy
  • To redeploy a context.xml file deployed by tomcat:deploy you can type:
    mvn tomcat6/7:redeploy

    Note: Depending on the docBase specified in the context.xml you may also need to call war:exploded or war:inplace as above.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Undeploying a WAR project【从服务器卸载项目】

To undeploy a WAR from Tomcat you can type:

mvn tomcat6/7:undeploy


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Starting a WAR project【启动一个项目】

To start a WAR in Tomcat you can type:

mvn tomcat6:start

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Stopping a WAR project【停止一个项目】

To stop a WAR in Tomcat you can type:

mvn tomcat6:stop

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

总结至此,希望能对大家有所帮助

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



maven自动化:部署项目到tomcat