maven 文件上传到远程服务器目录

23 篇文章 0 订阅
4 篇文章 0 订阅

目的:实现本地代码,或者程序包,或者单个配置文件,或者多个上传部署到服务器对应的目录中去。

问题1:用maven什么插件可以实现?

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.

下面给出我的POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.hdkg</groupId>
    <artifactId>upload</artifactId>
    <version>0.0.1</version>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>wagon-maven-plugin</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
<build>
    <finalName>upload</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>hdkg</serverId>
                <!-- 本地目录,从哪上传,这里指定不是目录,是单个文件 -->
<!--                <fromFile>target/dis/atc.jar</fromFile>-->
<!--                <fromFile>target/dis/resources/logback-spring.xml</fromFile>-->
                <fromFile>target/upload.jar</fromFile>
                <!-- 本地目录,从哪上传,这里指定的是目录,不是单个文件 -->
<!--                <fromDir>target/dis</fromDir>-->
                <!--   过滤你不想要的文件  -->
<!--                <excludes>logback-spring.xml</excludes>-->
                <!--远程目录,上传到哪去-->
              <toDir>/home/hdkg/ATC/temp</toDir>
                <!-- 服务器地址IP,如果没有toDir,写完整路径 -->
<!--                <url>scp://hdkg@100.100.100.154/home/hdkg/ATC/temp</url>-->
                <url>scp://hdkg@100.100.100.154</url>
<!--                <commands>-->
<!--                    &lt;!&ndash; 关闭tomcat &ndash;&gt;-->
<!--                    <command>/home/hadoop/apache-tomcat-8.0.5/bin/shutdown.sh</command>-->
<!--                    &lt;!&ndash; 删除之前解压后的目录 &ndash;&gt;-->
<!--                    <command>rm -rf /home/hadoop/apache-tomcat-8.0.5/webapps/osc-shop-->
<!--                    </command>-->
<!--                    &lt;!&ndash; 启动tomcat &ndash;&gt;-->
<!--                    <command>/home/hadoop/apache-tomcat-8.0.5/bin/startup.sh</command>-->
<!--                </commands>-->
                <!--是否显示Shell命令-->
                <displayCommandOutputs>true</displayCommandOutputs>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

我的pom文件名字是 upload.xml ,没有用pom.xml ,是因为有pom.xml了,这个upload.xml是单独为了上传文件用的

问题2:那么怎么单独执行这个upload.xml呢?

mvn wagon:upload-single -f upload.xml  这个是上传单独文件。例如jar包这样一类的

mvn wagon:upload -f upload.xml 这个是上传多文件,可以整个目录

官方示例:

http://www.mojohaus.org/wagon-maven-plugin/usage.html

 

问题3 :那么如果我想一次执行多个pom.xml文件该怎么办?

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值