【问题标题】:maven-antrun spawns process and exits on Windows 7maven-antrun 在 Windows 7 上生成进程并退出
【发布时间】:2018-02-09 15:38:06
【问题描述】:

我在构建中观察到一个奇怪的行为,我对如何调查一无所知。

在我的验收测试期间,我在预集成测试阶段使用 maven-antrun-plugin 来启动之前构建的 jar。然后故障安全应该开始针对 jar 运行测试。我有一些可用的现有项目,所以我复制了配置:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>start-application</id>
            <phase>pre-integration-test</phase>
            <configuration>
                <target>
                    <exec executable="cmd" dir="../" spawn="true" os="Windows 7">
                        <arg value="/c"/>
                        <arg value="launcher.bat"/>
                        <arg value="${project.version}"/>
                    </exec>
                    <exec executable="cmd" dir="../" spawn="true" os="Windows Server 2012 R2">
                        <arg value="/c"/>
                        <arg value="launcher.bat"/>
                        <arg value="${project.version}"/>
                    </exec>
                    <exec executable="./launcher.sh" dir="../" os="Linux">
                        <arg value="${project.version}"/>
                    </exec>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
</plugin>

但是,我看到了不同的行为。当我在一个适用的旧项目上执行 mvn -X clean install 时,我得到:

[INFO] Executing tasks
Build sequence for target(s) `main' is [main]
Complete build sequence is [main, ]

main:
     [exec] Current OS is Windows 7
     [exec] Executing 'cmd' with arguments:
     [exec] '/c'
     [exec] 'launcher.bat'
     [exec] '1.0.0-SNAPSHOT'
     [exec]
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.
Execute:Java13CommandLauncher: Executing 'cmd' with arguments:
'/c'
'launcher.bat'
'1.0.0-SNAPSHOT'

The ' characters around the executable and arguments are
not part of the command.
spawned process java.lang.ProcessImpl@5b6ba5bb
     [exec] Current OS is Windows 7
     [exec] This OS, Windows 7 was not found in the specified list of valid OSes: Windows Server 2012 R2
     [exec] Current OS is Windows 7
     [exec] This OS, Windows 7 was not found in the specified list of valid OSes: Linux
[INFO] Executed tasks
[INFO]
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (default) @ acceptance ---

然后测试执行..

现在在我的另一个项目中,我得到了这个:

[INFO] Executing tasks
Build sequence for target(s) `main' is [main]
Complete build sequence is [main, ]

main:
     [exec] Current OS is Windows 7
     [exec] Executing 'cmd' with arguments:
     [exec] '/c'
     [exec] 'launcher.bat'
     [exec] '1.0.0-SNAPSHOT'
     [exec]
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.
Execute:Java13CommandLauncher: Executing 'cmd' with arguments:
'/c'
'launcher.bat'
'1.0.0-SNAPSHOT'

The ' characters around the executable and arguments are
not part of the command.

D:\vincent\GIT\my_project\acceptance>

启动器可以工作,因为就像其他项目一样,我的 jar 会在另一个窗口中启动。但是,构建只是退出,而不是简单地使用故障安全执行测试! 日志不像其他情况那样显示生成的进程 java.lang.ProcessImpl@5b6ba5bb.. 即使它似乎确实生成了 launcher.bat。

我意识到我运行的不是完全相同版本的 antrun 插件,所以我将我的新项目降级到 1.7 以使其匹配。我在这两种情况下都使用 Java 8。

我真的没有什么想法可以调查了……有什么想法吗?

谢谢

【问题讨论】:

  • 你应该指出你正在使用的 Maven 版本,同时显示工作和不工作项目的整个 pom.xml。
  • 很可能launcher.bat是罪魁祸首。
  • 非常感谢@EugenCovaci,你的第二条评论让我走上了正轨——为什么它失败了是一个非常愚蠢的原因!

标签: java maven maven-antrun-plugin


【解决方案1】:

感谢 Eugen 对我的问题的评论,我对 launcher.bat 进行了更多调查,并用虚拟 echo/sleep/echo 替换了内容 -> 我的构建现在按预期继续,所以我知道我是对的路径。

launcher.bat 的内容是这样的:

cd /d %~dp0
echo "killing app before starting it"
call ./kill.bat

start %JAVA_HOME%\bin\java ...blablabla...

如果应用程序已经在运行,kill.bat 应该杀死应用程序,如果它没有从以前的构建中正确关闭。

现在,这是 kill.bat 的内容:

wmic process where (commandline like "%%my-app%%" and not name="wmic.exe") delete

好吧,你猜怎么着... maven 构建和我生成的应用程序(我在上面用 my-app 替换它)都匹配 where 子句 - 所以如果我的构建没有按预期完成,这是因为它被生成的进程杀死了,该进程应该杀死它以前运行的版本,而不是它的“父”构建!

注意:它似乎适用于不同版本的 Windows(如 Windows 10),其中 wmic 可能略有不同

【讨论】:

    猜你喜欢
    • 2013-09-18
    • 2011-01-25
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多