属性值:
<properties>
<ssh.ip>192.168.207.109</ssh.ip>
<ssh.username>root</ssh.username>
<ssh.pwd>1q2w3e4r5t</ssh.pwd>
<ssh.run.skip>false</ssh.run.skip>
<ssh.lib.skip>true</ssh.lib.skip>
<ssh.yml.skip>true</ssh.yml.skip>
<ssh.exec.skip>false</ssh.exec.skip>
</properties>
添加扩展依赖包:
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
</build>
添加插件plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<settings>
<servers>
<server>
<id>wagon-ssh</id>
<username>${ssh.username}</username>
<password>${ssh.pwd}</password>
</server>
</servers>
</settings>
<serverId>wagon-ssh</serverId>
<url>scp://${ssh.ip}</url>
<skip>false</skip>
</configuration>
<executions>
<execution>
<id>ssh-upload-yml</id>
<phase>package</phase>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<skip>${ssh.yml.skip}</skip>
<fromDir>target/classes</fromDir>
<toDir>${ssh.path}</toDir>
<includes>*.yml</includes>
</configuration>
</execution>
<execution>
<id>ssh-upload-lib</id>
<phase>package</phase>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<skip>${ssh.lib.skip}</skip>
<fromDir>target</fromDir>
<toDir>${ssh.path}</toDir>
<includes>lib/*</includes>
</configuration>
</execution>
<execution>
<id>ssh-upload-run</id>
<phase>package</phase>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<skip>${ssh.run.skip}</skip>
<fromDir>target</fromDir>
<toDir>${ssh.path}</toDir>
<includes>${project.build.finalName}.jar</includes>
</configuration>
</execution>
<execution>
<id>ssh-exec</id>
<phase>package</phase>
<goals>
<goal>sshexec</goal>
</goals>
<configuration>
<skip>${ssh.exec.skip}</skip>
<displayCommandOutputs>true</displayCommandOutputs>
<commands>
<command>mv ${ssh.path}/${project.build.finalName}.jar ${ssh.path}/run.jar</command>
</commands>
</configuration>
</execution>
</executions>
</plugin>