gpt4 book ai didi

java - 即使可执行文件在 Windows 上失败,Maven exec 插件也会构建成功

转载 作者:行者123 更新时间:2023-11-30 07:57:58 26 4
gpt4 key购买 nike

我有一个 Maven 项目,在其中使用 maven exec 插件执行 Windows .bat 文件。问题是,即使 bat 执行失败(即退出代码为 -1),项目的构建也是成功的。

这是我定义的插件:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>run.bat</executable>
</configuration>
</execution>
</executions>
</plugin>

请注意,如果我在 Unix 上执行它,其行为与预期相同(即执行 .sh 文件并构建失败)。

最佳答案

参见noahlz answer对于问题Launching a windows batch script using Maven exec plugin ... :

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

... 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.

如果 run.bat 中的命令设置了 %ERRORLEVEL%,则会在执行的 CMD 中设置此值,但不会传递给 CMD 的调用者,即 Maven Exec 插件。使用 EXIT %ERRORLEVEL% 退出 run.bat明确应该可以解决问题。

关于java - 即使可执行文件在 Windows 上失败,Maven exec 插件也会构建成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32403099/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com