使用wagon-maven-plugin插件自动部署项目到远程服务器,并执行shell脚本

1、在本地maven的settings.xml中的servers节点,增加一个server配置。id随便取,唯一即可,username是远程服务器的登录用户名,password是远程服务器的密码

复制代码
<server>
    <id>webserver</id>
    <username>root</username>
    <password>123456</password>
</server>

2、在maven项目的pom文件中增加以下配置:

复制代码
<build>
    <extensions>
        <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-ssh</artifactId>
            <version>2.8</version>
        </extension>
    </extensions>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>wagon-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <id>upload-deploy</id>
                    <phase>package</phase>
                    <goals>
                        <goal>upload-single</goal>
                        <goal>sshexec</goal>
                    </goals>
                    <configuration>
                        <serverId>webserver</serverId>
                        <fromFile>target/project.jar</fromFile>
                        <url>scp://root@10.105.17.201/root/project</url>
                        <commands>
                            <command>/root/project/boot.sh start</command>
                        </commands>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

2、execution中的id随便取;phase表示在maven的package之后执行上传;goals指定执行wagon插件的任务列表,这里指定两个:一个上传,一个执行shell命令;configuration中的serverId对应上面添加的server的id;fromFile是待上传的文件路径;url是上传的远程服务器地址;格式为:scp://username@ip/path;command节点可以添加shell命令或运行shell脚本,支持同时添加多个command;

3、执行maven的clean package即可自动部署jar包/war包到远程服务器并执行指定shell脚本

当然,wagon-maven-plugin还可以通过其他配置来部署应用,对应的也可以通过clean wagon:upload wagon:sshexec 等命令来执行上传、运行shell等功能。

相关推荐
Android系统攻城狮7 小时前
Linux FFmpeg深度解析之avcodec_align_dimensions调用流程与实战(二十九)
服务器·linux音视频·音视频进阶·ffmpeg音视频
金銀銅鐵7 小时前
为什么枚举类中可以定义抽象方法
java·后端·ai编程
叼烟扛炮8 小时前
Linux 学习笔记(五十六):IO 多路复用初探——select 的“三宗罪”
linux·服务器·数据库·笔记·学习·php
Ruiery8 小时前
Linux 6.6内核内存管理深度解析(十五):CMA 连续内存分配器
linux·运维·服务器
文丑颜不良啊9 小时前
LeetCode1941~1960题目解析
java·leetcode
测试界的小码农9 小时前
【Linux 命令实战(01):认识 Linux 终端,从零掌握第一个命令】
linux·运维·服务器
txxzjmzlh9 小时前
SpringBoot 统⼀功能处理
java·spring boot·后端
zhikouai10 小时前
把外部助手接进聊天软件的架构分层与参数配置
服务器·网络·php
荣合技术服务10 小时前
HPC 超算集群故障维修实录:找荣合科算维护后,模拟仿真计算又能跑了
运维·服务器·超算服务器·荣合科算
nice_lcj52011 小时前
Java Lambda 表达式入门:怎么写、怎么用、常用方法有哪些
java·开发语言·后端·面试