![](/img/trans.png)
[英]Use exec-maven-plugin to execute shell script on Windows
[英]Using maven plugin exec-maven-plugin to run a shell script
我有一个Java Web应用程序项目。 我正在使用exec-maven-plugin执行shell脚本,当使用mvn clean isntall构建项目时,该脚本会在目录中创建一个小的txt文件。 我已经通过编写测试文本确认了在运行mvn clean install时正在执行脚本。 但是,该脚本不会创建txt文件。
当脚本通过终端正常运行时,即./script.sh,将正确创建txt文件。
toTxt="hello"
printf $toTxt > testText.txt
echo 'This shows up, but testText is not created.'
有人知道为什么会这样吗?
尝试用<workingDirectory>${project.build.outputDirectory}</workingDirectory>
pwd
命令查看应在何处创建文件,或将<workingDirectory>${project.build.outputDirectory}</workingDirectory>
到pom.xml中的配置块中。注:您可以指定${project.build.outputDirectory}
专门指向正确的位置。 并确保您对此具有写权限。
请记住,某些命令不是真正的外部程序,而是Shell内置程序。 这意味着它们不会启动程序,并且maven-exec-plugin将无法运行它们。 但是 ,您可以运行bash
以获得结果,而不是pwd
。
bash -c "echo $(pwd)"
应该可以。 Maven正在启动bash
,然后运行脚本echo $(pwd)
,该脚本调用bash内置函数pwd
并将结果传回(由于echo)。
是的,要克服缺少pwd
程序的工作量很大,但这是因为确实没有pwd
程序,它是bash
内部产品的一部分。
http://www.tldp.org/LDP/abs/html/internal.html列出了bash内部结构(内置命令)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.