Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven copy local file to remote server using SSH

Can Maven copy local file to a remote server using SSH?

I want to specify location in maven configuration file and to copy that file (or files) to server each time deploy phase is executed.

like image 740
mgamer Avatar asked May 26 '09 09:05

mgamer


People also ask

How do I copy files from one directory to another in Maven?

Using the Copy Rename Maven Plugin The copy-rename-maven-plugin helps copying files or renaming files/directories during the Maven build lifecycle. Upon building the project, we'll see foo. txt in the target/destination-folder.

How does maven deploy work?

deploy:deploy is used to automatically install the artifact, its pom and the attached artifacts produced by a particular project. Most if not all of the information related to the deployment is stored in the project's pom. deploy:deploy-file is used to install a single artifact along with its pom.


3 Answers

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.

I believe this will replace the normal deployment instead of add to it, so it may not be what you're after.

If you need to deploy to a traditional Maven repository as well as deliver the file to the remote server, you will need to use the scp task as the other answers suggest.

In this answer I've described how to configure the ftp task, the scp task is almost identical except you may need to add the keyfile and passphrase attributes (and change the task name from ftp to scp obviously).

like image 107
Rich Seller Avatar answered Oct 17 '22 22:10

Rich Seller


Have a look at Maven Wagon plugin

To try it manually with a simple command line: mvn org.codehaus.mojo:wagon-maven-plugin:1.0:upload -Dwagon.url=scp://username:userpassword@myserver -Dwagon.fromDir=target -Dwagon.includes=*.ear -Dwagon.toDir=/home/elisabetta

In both cases, be sure to add the SSH extension for Wagon to your pom.xml:

<extensions>
    <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ssh</artifactId>
        <version>2.8</version>
    </extension>
</extensions>
like image 21
PaoloC Avatar answered Oct 17 '22 21:10

PaoloC


Why not use the Ant SCP task, which you can run within Maven?

like image 14
Brian Agnew Avatar answered Oct 17 '22 21:10

Brian Agnew