maven自动化:部署项目到tomcat

来源:互联网 发布:阿里云注销 编辑:程序博客网 时间:2024/05/01 09:31

1. tomcat中配置用户

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

|-- tomcat-users.xml

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

 

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <role rolename="manager-gui"/>  
  2. <user username="admin" password="admin" roles="manager-gui"/>   

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

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

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

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


[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <servers>  
  2.   
  3.   ……  
  4.   
  5.  <!-- 配置部署项目的tomcat服务器 -->  
  6.  <server>  
  7.       <id>myserver</id>  
  8.       <username>admin</username>  
  9.       <password>admin</password>  
  10.     </server>  
  11.   
  12. ……  
  13.   
  14. </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了,以后在你的项目中必须按照以下的方式进行配置

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


[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <pluginManagement>  
  2.       <plugins>  
  3.   
  4.         <!-- 配置tocmat6插件 -->  
  5.         <plugin>  
  6.           <groupId>org.apache.tomcat.maven</groupId>  
  7.           <artifactId>tomcat6-maven-plugin</artifactId>  
  8.           <version>2.3-SNAPSHOT</version>  
  9.         </plugin>  
[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <!-- 配置tocmat7插件 -->  
  2.         <plugin>  
  3.           <groupId>org.apache.tomcat.maven</groupId>  
  4.           <artifactId>tomcat7-maven-plugin</artifactId>  
  5.           <version>2.3-SNAPSHOT</version>  
  6.         </plugin>  
  7.       </plugins>  
  8.     </pluginManagement>  

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

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

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

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <pluginGroups>  
  2.     ....  
  3.     <pluginGroup>org.apache.tomcat.maven</pluginGroup>  
  4.     ....  
  5.   </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

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

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

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


0 0
原创粉丝点击