maven实现项目远程部署到tomcat(热部署)

http://shellblog.sinaapp.com/?p=66


1.配置远程的tomcat7,修改conf下的 tomcat-users.xml文件,如下:

1
2
3
4
<role rolename= "manager-gui" />
     <role rolename= "manager-script" />
     <user username= "tomcat" password= "tomcat" 
             roles= "manager-gui,manager-script" />

2.在POM中加入部署插件,如下:

1
2
3
4
5
6
7
8
<plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>tomcat-maven-plugin</artifactId>
         <configuration>
             <url>http: //192.168.5.231:8585/manager/html</url>
             <server>test</server>
         </configuration>
     </plugin>

 
3.修改maven配置文件:settings.xml,在其中加入test的配置:

1
2
3
4
5
<server>
        <id>test</id>
        <username>tomcat</username>
        <password>tomcat</password>
    </server>

4.配置完成,执行命令:

1
mvn tomcat:redeploy

 
上述方式为tomcat热部署,不需要重启服务器。



上面方法适合web 项目并且是热部署,下面是一种自动打包并上传的办法

主要插件:

wagon:upload-single

Full name:

org.codehaus.mojo:wagon-maven-plugin:1.0-beta-4:upload-single

Description:

Upload a single file with option to change name

Attributes:

Required Parameters

Name Type Since Description
fromFile File - Path to a local file to be uploaded
url String - URL to upload to or download from or list. Must exist and point to a directory.

Optional Parameters

Name Type Since Description
serverId String - settings.xml's server id for the URL. This is used when wagon needs extra authentication information.
Default value isserverId.
skip boolean - When true, skip the execution.
Default value isfalse.
toFile String - Relative path to the URL. When blank, default to fromFile's file name.
下面是具体配置 :

<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>1.0</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.ifeng.tcp.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<id>upload-war</id>
<phase>package</phase>
<goals>
<goal>upload-single</goal>
</goals>
<configuration>
<fromFile>target\${project.artifactId}-${project.version}.${project.packaging}</fromFile>
<url>scp://172.30.22.61/data</url>
<serverId>deploy</serverId>
</configuration>
</execution>
</executions>


</plugin>

</plugins>
</build>


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值