我的项目 pom 包含 gmaven-plugin
插件,其中在 configuaration->properties->script
标签下定义了 sh 脚本位置,当我执行 时mvn install
,我在 Windows 机器上遇到以下错误。
java.io.IOException:
Cannot run program ": CreateProcess error=193, %1 is not a valid Win32 application
请找到以下相关插件。
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<script>${basedir}/../tools/testfile.sh</script>
</properties>
<source>
//some code for execution
</source>
</configuration>
</execution>
</executions>
</plugin>
最佳答案
您正在尝试在 Windows 计算机上执行 shell 脚本。 window 命令不知道如何做到这一点。这可能是造成问题的原因。
如果您想对此进行测试,只需将 shell 替换为简单的 .bat
文件(Windows 可执行文件)即可。
您可以将以下内容添加到.bat
文件中并尝试mvn install
echo Test file executed.
echo I am too lazy to write commands again and again.
编辑:正如OP通过评论告知
.bat file is executing successfully from when executing mvn install command but what if you want to execute only .sh file only. Is there any way for it.
现在选项是在 Windows 上执行 .sh
。很少有选择安装 GIT client ,默认情况下安装 GIT BASH
这是一个类似 UNIX 的命令提示符。
安装后,只需从 Windows 打开任何 .sh
文件并说 open with..
并选择 GIT BASH
。单击始终使用此程序
。此步骤会将 .sh
关联到 git bash 程序。
另一个常见的解决方案是使用 Cygwin
关于java - 无法在Windows中的java maven项目中执行shell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49200333/