【问题标题】:I want to write a shell script which will take mvn clean test command as input and when I run the script , it should run my maven project我想编写一个 shell 脚本,它将 mvn clean test 命令作为输入,当我运行脚本时,它应该运行我的 maven 项目
【发布时间】:2018-05-31 23:19:04
【问题描述】:

我使用 Java 和 TestNG 创建了一个 maven 项目。我想批量运行我的测试,所以我把它们放在testing.xml 文件中。我可以使用以下命令从命令行成功运行testing.xml 文件

mvn clean test -Dsurefire.suiteXmlFiles=testng.xml

现在我想写一个shell脚本,它将上面的命令作为输入,当我运行.sh文件时,它应该反过来运行testing.xml文件。

请有人建议是否可能,以及如何。

【问题讨论】:

  • 我不确定我是否理解清楚,但你想制作一个运行mvn clea test -Dsure … 命令的.sh 脚本吗?
  • 你问的不是很清楚?
  • @Martin,你明白我的意思。
  • @SheetalMohanSharma Martin 解释了我的问题

标签: java shell maven selenium


【解决方案1】:

所以您想将命令传递给脚本,然后脚本运行该命令? 将以下内容放入您的脚本文件(例如名为 yourscript.sh):

#!/bin/bash
echo 'Executing '$1' ...'
$1
if [ $? == 0 ]; then
    echo 'command successfully executed'
else
    echo 'something went wrong :('
fi

这样调用你的脚本:./yourscript.sh 'mvn clean test -Dsurefire.suiteXmlFiles=testng.xml'

然后您的脚本应该运行该命令并通知您它是否成功。

【讨论】:

  • 这种脚本有什么意义?好像没什么用,因为没有错误处理什么的
  • 好问题,我也想知道为什么有人需要这个特定的功能。也许我只是误解了 OP ...
  • 大家好,我找到了解决方案。我只需要创建一个 .sh 文件并添加以下内容。 #!/bin/bash cd /path/to/your/project/directory mvn clean test -Dsurefire.suiteXmlFiles=testng.xml 感谢大家的帮助和支持。
猜你喜欢
  • 1970-01-01
  • 2023-04-11
  • 1970-01-01
  • 1970-01-01
  • 2019-10-19
  • 2021-09-08
  • 2018-11-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多