本文介绍了使用Maven exec插件启动Windows批处理脚本会阻止构建,即使该脚本使用“开始"脚本也是如此.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在自定义容器顶部执行应用程序部署的集成品尝.由于我的容器是自定义的,因此我无法使用Maven Cargo插件来设置容器.

I am trying to perform integration tasting of the deployment of my application on the top of a custom container. Since my container is custom, I cannot use Maven Cargo plugin to setup the container.

我的容器:

  • 必须通过正确的bat文件启动,该文件位于运行测试的计算机的路径中.
  • 由于我只有一个包含所有集成测试的maven模块,因此可以手动关闭,即使有一天我想知道如何在测试完成后关闭该过程.

我的问题是我必须在不同的进程中运行容器,因为在执行测试时它需要保持运行.此外,我在测试中有一个API,可以让我等待容器准备就绪(一种具有超时的查找方式).

My problem is that I have to run my container in a different process, because it needs to keep running while my tests are performed. Furthermorely, I have an API in my tests that let me wait for the container to be ready (a sort of lookup with timeout).

我在pom.xml中添加了以下几行

I have added the following lines to my pom.xml

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <executable>scripts/start-agent.bat</executable>
            </configuration>
        </plugin>

这将调用一个仅包含

但是mvn exec插件卡住了,我的测试未运行.根据>如何运行我的Java应用程序中有一个批处理文件?,我将pom.xml修改如下:

However the mvn exec plugin gets stucked and my tests are not run. According to what is suggested in How do I run a batch file from my Java Application? , I have modified my pom.xml as the following:

 <configuration>
                <executable>cmd</executable>
                <arguments>
                    <argument>/C</argument>
                    <argument>start</argument>
                    <argument>gs-agent.bat</argument>
                </arguments>
            </configuration>

但这似乎无法解决问题:

But this does not seem to solve the issue:

推荐答案

查看此问题:

Windows批处理文件不可执行.它们是由cmd可执行文件运行的脚本.

Windows Batch Files are not executable. They are scripts that are run by the cmd executable.

更多信息

Exec插件源代码显示 Apache Commons Executor 用于实际执行命令行.

Exec plugin source code reveals that Apache Commons Executor is used to actually execute the command line.

您可以在此处进行大量阅读,例如,在Apache Commons Executor文档及其 JIRA问题,但简短的版本是:这不是"Maven"的问题,而是与执行exec()命令有关的平台相关的问题.

There is a lot of reading you can do here, i.e. in the Apache Commons Executor documentation and their JIRA issues, but the short version is: this isn't a problem with "Maven," it's a problem with the platform-dependent nature of executing an exec() command.

我之前已经解决了此类问题,我一直设计的解决方案是将.bat脚本分解为实际命令,并直接从exec插件启动它,而不是调用该脚本.

I've tackled this sort of problem before, and the solution I always devise is to deconstruct the .bat script into its actual commands and launch it directly from the exec plugin, rather than calling the script.

这篇关于使用Maven exec插件启动Windows批处理脚本会阻止构建,即使该脚本使用“开始"脚本也是如此.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 00:00