【发布时间】:2016-06-30 00:12:03
【问题描述】:
我想在 mvn 中使用 antrun 运行 ssh 和 scp 命令。
ssh & scp 命令正确运行,并且在下一阶段声明的插件 - 运行。
但是 ssh/scp 之后的所有命令的输出 - 不会写入任何输出!
有什么问题?!
这是我的 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>0.0.0-1-SNAPSHOT</version>
<name>name</name>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>echoKuku</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<sshexec verbose="true" output="o.txt" failonerror="false" host="${Ip}" trust="yes"
username="${UserName}" command="echo kuku" keyfile="${Keyfile}" />
<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
classpathref="maven.plugin.classpath" />
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>jsch</groupId>
<artifactId>jsch</artifactId>
<version>0.1.29</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>download-jsch</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<overWriteSnapshots>true</overWriteSnapshots>
<artifactItems>
<artifactItem>
<groupId>jsch</groupId>
<artifactId>jsch</artifactId>
<version>0.1.29</version>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<javaVersion>1.7</javaVersion>
<Ip>1.2.3.4</Ip>
<UserName>root</UserName>
<Keyfile>${user.home}/.ssh/id_rsa</Keyfile>
</properties>
<dependencies>
<dependency>
<groupId>jsch</groupId>
<artifactId>jsch</artifactId>
<version>0.1.29</version>
</dependency>
</dependencies>
</project>
文件 jsch-0.1.29.jar 已在目标目录中创建,但输出为:
C:\Users\azberger\somePath>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building name 0.0.0-1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The artifact jsch:jsch:jar:0.1.29 has been relocated to com.jcraft:jsch:jar:0.1.29
[INFO]
[INFO] --- maven-antrun-plugin:1.6:run (echoKuku) @ artifact ---
[INFO] Executing tasks
main:
[sshexec] Connecting to 1.2.3.4:22
kuku
C:\Users\azberger\somePath>
更新:(格林威治标准时间 16 年 3 月 3 日 8:11)
scp - 工作正常。
带有文件脚本 (commandResource="[file]") 的 sshexec - 工作正常。
sshexec 使用单个命令 (command="[command]") - 导致问题,如上所述。
【问题讨论】:
-
当然。这是我用的插件!