您的位置:首页 > 编程语言 > Go语言

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

2018-03-20 14:11 711 查看
该插件的maven依赖为:

[html] view
plain copy

<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的用户名和密码。

[html] view
plain copy

<server>  

    <id>webserver</id>  

    <username>hadoop</username>  

    <password>123</password>  

</server>  

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

[html] view
plain copy

<extensions>  

    <extension>  

        <groupId>org.apache.maven.wagon</groupId>  

        <artifactId>wagon-ssh</artifactId>  

        <version>2.10</version>  

    </extension>  

</extensions>  

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

[html] view
plain copy

<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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: