使用wagon-maven-plugin插件自动部署项目

该插件的maven依赖为:

<dependency>  
    <groupId>org.codehaus.mojo</groupId>  
    <artifactId>wagon-maven-plugin</artifactId>  
    <version>1.0</version>  
</dependency>  

插件的文档地址为:
http://www.mojohaus.org/wagon-maven-plugin/

主要提供如下几个goal
wagon:upload-single uploads the specified file to a remote location.
wagon:upload uploads the specified set of files to a remote location.
wagon:download-single downloads the specified file from a remote location.
wagon:download downloads the specified set of files from a remote location.
wagon:list lists the content of a specified location in a remote repository.
wagon:copy copies a set of files under a Wagon repository to another.
wagon:merge-maven-repos merges , including metadata, a Maven repository to another.
wagon:sshexec Executes a set of commands at remote SSH host.

用法如下:

为了让wagon-maven-plugin插件能SSH连上Linux服务器,首先需要在Maven的配置文件settings.xml中配置好server的用户名和密码。

<server>  
    <id>webserver</id>  
    <username>hadoop</username>  
    <password>123</password>  
</server>  

使用该插件,需要在build里面配置如下内容

<extensions>  
    <extension>  
        <groupId>org.apache.maven.wagon</groupId>  
        <artifactId>wagon-ssh</artifactId>  
        <version>2.10</version>  
    </extension>  
</extensions>  

如下演示了一个,使用该查询部署一个war到tomcat的过程

<build>  
    <finalName>osc-shop</finalName>  
    <extensions>  
        <extension>  
            <groupId>org.apache.maven.wagon</groupId>  
            <artifactId>wagon-ssh</artifactId>  
            <version>2.10</version>  
        </extension>  
    </extensions>  
    <plugins>  
        <plugin>  
            <groupId>org.codehaus.mojo</groupId>  
            <artifactId>wagon-maven-plugin</artifactId>  
            <version>1.0</version>  
            <configuration>  
                <serverId>webserver</serverId>  
                <!-- 需要部署的文件 -->  
                <fromFile>target/osc-shop.war</fromFile>  
                <!-- 部署目录 -->  
                <url>scp://hadoop@192.168.1.222/home/hadoop/apache-tomcat-8.0.5/webapps/  
                </url>  
                <commands>  
                    <!-- 关闭tomcat -->  
                    <command>/home/hadoop/apache-tomcat-8.0.5/bin/shutdown.sh</command>  
                    <!-- 删除之前解压后的目录 -->  
                    <command>rm -rf /home/hadoop/apache-tomcat-8.0.5/webapps/osc-shop  
                    </command>  
                    <!-- 启动tomcat -->  
                    <command>/home/hadoop/apache-tomcat-8.0.5/bin/startup.sh</command>  
                </commands>  
                <displayCommandOutputs>true</displayCommandOutputs>  
            </configuration>  
        </plugin>  
    </plugins>  
</build> 

配置完成后,执行命令
mvn clean package wagon:upload-single wagon:sshexec
即可部署到服务器,并且重启了tomcat

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值