Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用maven执行shell脚本_Java_Shell_Maven - Fatal编程技术网

Java 如何使用maven执行shell脚本

Java 如何使用maven执行shell脚本,java,shell,maven,Java,Shell,Maven,我的设想: 我已经在服务器上部署了某些测试文件,我想使用maven在远程服务器上运行一个shell脚本。现在的语言没有maven插件,所以我就是这样做的。shell脚本将运行测试并生成.txt格式的输出 我的问题是: 我已经使用maven ant运行插件成功地运行了脚本,但它没有显示maven输出。在执行脚本之后,运行maven时的输出不会在它之后显示任何内容。所以在这种情况下,使用maven ant run并不理想。这是我的POM.xml的一部分: <plugin>

我的设想: 我已经在服务器上部署了某些测试文件,我想使用maven在远程服务器上运行一个shell脚本。现在的语言没有maven插件,所以我就是这样做的。shell脚本将运行测试并生成.txt格式的输出

我的问题是: 我已经使用maven ant运行插件成功地运行了脚本,但它没有显示maven输出。在执行脚本之后,运行maven时的输出不会在它之后显示任何内容。所以在这种情况下,使用maven ant run并不理想。这是我的POM.xml的一部分:

<plugin>
            <!-- Step to copy the unit tests to designated destination -->
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>Deploy Unit tests onto Server</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target>
                            <!-- Copy files to the remote integration test server -->
                            <!-- Transferring unit tests -->
                            <scp failonerror="true" todir="${scp.user}:${scp.password}@${scp.host}:/${scp.dirCopyToUnit}" trust="true">
                                <fileset dir="${scp.UnitTest.api.dir}">
                                    <include name="*"></include>
                                </fileset>
                            </scp>
                            <!-- transferring resources files -->
                            <scp failonerror="true" todir="${scp.user}:${scp.password}@${scp.host}:/${scp.dirCopyToUnitResources}" trust="true">
                                <fileset dir="${scp.UnitTest.api.dirResources}">
                                    <include name="*"></include>
                                </fileset>
                            </scp>
                            <!-- transferring spec_helper.lua -->
                            <scp failonerror="true" todir="${scp.user}:${scp.password}@${scp.host}:/${scp.dirCopySpec_Helpers}" trust="true">
                                <fileset dir="${scp.UnitTest.api.dirSpec_Helpers}">
                                    <include name="*"></include>
                                </fileset>
                            </scp>
                            <sshexec command="sh /tmp/unitTestMaven.sh exit exit" host="${scp.host}" password="${scp.password}" trust="yes" username="${scp.user}"></sshexec>
                            <taskdef classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" classpathref="maven.plugin.classpath" name="sshexec"></taskdef>
                        </target>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.jcraft</groupId>
                    <artifactId>jsch</artifactId>
                    <version>0.1.53</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.ant</groupId>
                    <artifactId>ant-jsch</artifactId>
                    <version>1.8.4</version>
                </dependency>
            </dependencies>
        </plugin>

我也尝试过使用旅行车插件:

 <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>wagon-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <id>execute-test-commands</id>
                    <phase>test</phase>
                    <goals>
                        <goal>sshexec</goal>
                    </goals>
                    <configuration>
                        <serverId>atlassian-public</serverId>
                        <url>"scp://${scp.user}:${scp.password}@${scp.host}"</url>
                        <commands>
                            <command>sh /tmp/unitTestMaven.sh</command>
                        </commands>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

org.codehaus.mojo
货车司机插件
1
执行测试命令
测试
sshexec
大西洋公众
“scp://${scp.user}:${scp.password}@${scp.host}”
sh/tmp/unitTestMaven.sh

但是出现以下错误:
org.apache.maven.lifecycle.LifecycleExecutionException:无法在项目aa上执行目标org.codehaus.mojo:wagen-maven插件:1.0:sshexec(执行测试命令):无法创建一个wagen实例

看起来您正在尝试使用一些集中的“测试”服务器,使用jenkins如何?此外,在运行mvn-X时,您还应该发布使用
mvn-X
获得的输出,它在执行脚本后也会暂停发布输出您是否尝试等待,我的意思是,脚本可能需要一些时间才能运行?构建确实运行,但没有显示任何内容。Maven在运行脚本后不会在屏幕上打印出来。我知道它是运行的,因为有一些文件是作为maven构建的一部分传输的。Maven-X在运行脚本后仍然会暂停,我理解这一点,但是
/tmp/unitTestMaven.sh
脚本是否完成,如果是,您如何知道。您也可以尝试在
sshexec
上使用
verbose=“yes”
,看起来您正在尝试使用一些集中的“测试”服务器,使用jenkins怎么样?此外,在运行mvn-X时,您还应该发布使用
mvn-X
获得的输出,它在执行脚本后也会暂停发布输出您是否尝试等待,我的意思是,脚本可能需要一些时间才能运行?构建确实运行,但没有显示任何内容。Maven在运行脚本后不会在屏幕上打印出来。我知道它是运行的,因为有一些文件是作为maven构建的一部分传输的。Maven-X在运行脚本后仍然会暂停,我理解这一点,但是
/tmp/unitTestMaven.sh
脚本是否完成,如果是,您如何知道。您还可以尝试在
sshexec
上使用
verbose=“yes”