Support

Forums

Contact Me

Apache Maven copy local file to a remote server server using SSH

I will show you in an Apache Maven configuration file how to copy files to server each time the package phase is executed.

Solution with Ant SCP task

This snippet of code is a ready to use code that make use of Apache Ant task scp, Just put this snippet of code in your Maven module where the assembly is executed or anywhere else to push all tar.gz files to a server just run a maven mvn package, you can add as many ant task and push to many server the same file during the reactor build.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
    <id>server-copy</id>
    <goals>
        <goal>run</goal>
    </goals>
    <phase>package</phase>
    <configuration>
        <target>
            <echo message="Push to server/home/"/>
            <scp trust="yes"
                todir="user:password@server:/home/">
                <fileset dir="${basedir}/target">
                    <include name="**/*.tar.gz"/>
                </fileset>
            </scp>
        </target>
    </configuration>
</execution>
</executions>
<dependencies>
<dependency>
    <groupId>org.apache.ant</groupId>
    <artifactId>ant-jsch</artifactId>
    <version>1.8.2</version>
</dependency>
</dependencies>
</plugin>

Solution with maven-deploy-plugin

The maven-deploy-plugin allows you to configure the deploy phase to deploy to a server using scp. There is a page in the documentation that describes how it can be done.

Deploy maven artifact using Maven Wagon SCP

Another alternative would be to use Maven Wagon SCP like described in this post for example

You might also like:
Easily Compress Web Application Resources with EhCache
217 days ago
Easily Compress Web Application Resources with EhCache
Resources such as JavaScript and CSS files can be compressed before being sent to the browser, imp
Tomcat 7 and Apache Maven
217 days ago
Tomcat 7 and Apache Maven
Here is 3 different way to control the lifetime a local Tomcat 7 container using Apache Maven. A t
Apache M2Eclipse: Get rid of Duplicate resources when openin
411 days ago
Apache M2Eclipse: Get rid of Duplicate resources when openin
In this small post, I’ll show you how to remove duplicated resources in the Open Resource view o
Apache Maven 3 Cookbook
553 days ago
Apache Maven 3 Cookbook
  First a big thanks to Packt Publishing for having sent me this book to review! I did enj
Apache Maven 3 Cookbook Review
599 days ago
Apache Maven 3 Cookbook Review
Thanks to Packt Publishing for having sent me this book to review. I will publish a review in the
List conflicting dependencies in the Maven reactor
715 days ago
List conflicting dependencies in the Maven reactor
The Maven Dependency Plugin among other things include a dependency:analyze-duplicate The depe
blog comments powered by Disqus

Donations

Thank You for supporting my work