Maven will copy the local file to the remote server using SSH

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

I want to specify the location in the maven configuration file and copy this file (or files) to the server at each stage of deployment.

+50
maven-2 ssh deployment
May 26 '09 at 9:49 a.m.
source share
6 answers

The maven-deploy-plugin module allows you to configure the deployment phase for deployment to the server using scp. The documentation has a page that describes how to do this.

I believe that this will replace the usual deployment instead of adding to it, so this may not be what you need.

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

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

+35
Sep 10 '09 at 16:51
source share

Why not use the Ant SCP task you can run in Maven?

+15
May 26 '09 at 10:39 a.m.
source share

Check out the Maven Wagon plugin

Try manually using 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> 
+11
Mar 23 '15 at 11:05
source share

Maven is not a universal tool, it is a tool to make your build process reusable. I suggest using the built-in antrun step. In this step, you can do everything using the regular ant syntax that you would use in the build.xml file.

+6
May 26 '09 at 10:17
source share

Although this question is not entirely new, today I found myself in a similar situation. My goal is to upload files and run commands on a remote server to which I have to connect (via another server). I was able to create a solution for this using ant (which can again be launched from maven, as indicated here).

Ants task sshsession only creates a tunnel that you can use for tasks inside. Tasks inside do not start automatically on the remote server, but you can use the sshexec task along with the tunnel to achieve this. Also, the scp task can now be loaded through the tunnel to a remote server. Here is an example:

 <sshsession host="${jumphost}" port="22" username="${user}" password="${password}" trust="true"> <localtunnel lport="${localTunnelPort}" rhost="${targethost}" rport="22"/> <sequential> <!-- run a command on the remote server (here mkdir) --> <sshexec host="localhost" port="${localTunnelPort}" username="${user.param}" password="${password.param}" command="mkdir ${home}/foobar" trust="true" /> <!-- upload a file to the remote server --> <scp port="${localTunnelPort}" file="test_file.txt" todir="${user.param}:${password.param}@localhost:${home}/foobar/" trust="true" /> </sequential> </sshsession> 
+2
Aug 14 '14 at 16:28
source share

The same ideas as PaoloC, using the Maven Wagon plugin with the extension wagon-ssh, but configuration in the pom file and launching at the specified phase, in these examples the military file is copied to a remote server with SSH

 <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>wagon-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <id>upload-to-myserver</id> <phase>deploy</phase> <goals> <goal>upload-single</goal> </goals> <configuration> <fromFile>${project.build.directory}/${project.build.finalName}.war</fromFile> <url>scp://username@myserver/path</url> </configuration> </execution> </executions> </plugin> <!-- other plugins ... --> </plugins> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh</artifactId> <version>2.8</version> </extension> </extensions> </build> 

The <phase> is optional. You can only start the download with the command:

 mvn wagon:upload-single@upload-to-myserver 
0
Aug 11 '17 at 15:30
source share



All Articles