我在构建中观察到一种奇怪的行为,而且我对如何调查毫无头绪。
在我的验收测试期间,我在预集成测试阶段使用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.
我真的没有想法去调查......有什么想法吗?
由于
答案 0 :(得分:0)
感谢Eugen对我的问题的评论,我对launcher.bat进行了更多调查,并用虚拟回声/睡眠/回声替换了内容 - &gt;我的版本现在按预期继续进行,所以我知道我走的是正确的道路。
launcher.bat的内容是这样的:
cd /d %~dp0
echo "killing app before starting it"
call ./kill.bat
start %JAVA_HOME%\bin\java ...blablabla...
如果应用程序已经在运行,它应该会终止该应用程序,如果它没有从之前的构建中正确关闭的话。
现在,这是kill.bat的内容:
wmic process where (commandline like "%%my-app%%" and not name="wmic.exe") delete
好吧,猜猜是什么...... maven构建和我生成的应用程序(我用 my-app 替换它)匹配where子句 - 所以如果我的构建没有按预期完成,这是因为它被生成的进程杀死了,这应该会杀死它以前运行的版本,而不是它的“父”版本!
注意:它似乎适用于不同版本的Windows(如Windows 10),其中wmic可能略有不同