maven antrun ssh或scp隐藏输出 [英] maven antrun ssh or scp hides the output

查看:88
本文介绍了maven antrun ssh或scp隐藏输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行ssh&在mvn中使用antrun的scp命令.
SSH& scp命令正确运行,并且在下一个阶段中声明的插件运行. 但是ssh/scp之后的所有命令的输出-不会写入任何输出!

I want to run an ssh & scp commands using antrun in mvn.
the ssh & scp commands runs correctly, and the plugins that declared inthe next phases - run. but the output of all commands after the ssh/scp - isn't written to any output!

出什么问题了?!

这是我的pom.xml:

here is my 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,但输出为:

the file jsch-0.1.29.jar was created in the target dir, but the output is:

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/16 8:11)

scp-工作正常.
带有文件脚本(commandResource ="[file]")的sshexec-正常工作.
带有单个命令(command ="[command]")的sshexec-导致问题,如上所述.

scp - works fine.
sshexec with a file script (commandResource="[file]") - works fine.
sshexec with a single command (command="[command]") - causes problem, as mention above.

推荐答案

尝试使用较新版本的JSCH依赖项(ant-jsch为1.8.4,jsch为0.1.53,每个都有不同的组ID).它解决了我这方面的问题:

Give it a try with newer versions of JSCH dependencies (1.8.4 for ant-jsch and 0.1.53 for jsch, each with different group ids). It fixed the problem on my side:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>server-copy</id>
            <goals>
                <goal>run</goal>
            </goals>
            <phase>process-sources</phase>
            <configuration>
                <target>
                    <echo message="Pushing to host..." />
                    <sshexec host="hostname" username="user" trust="true" 
                        password="pass" failonerror="true"  
                        command="mkdir -p /home/user/test/test"/> 
                    <scp trust="yes"
                        file="some-file"
                        todir="user:pass@hostname:/path/to/some-file" 
                        />
                </target>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-jsch</artifactId>
            <version>1.8.4</version>
        </dependency>
        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.53</version>
        </dependency>
    </dependencies>
</plugin>

这篇关于maven antrun ssh或scp隐藏输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆