如何在linux中使用sh文件运行maven项目

时间:2018-04-20 13:12:48

标签: linux shell maven batch-file

对于Windows系统,我使用批处理文件和以下命令:

echo off
call mvn -f MyApp\pom.xml clean install -U
set /p delExit=Press the ENTER key to exit...:

它在Windows中运行良好。

我想使用sh文件从Linux系统中使用run Maven项目。

请让我知道sh命令,它们与上面的windows批处理命令相同。

感谢。

3 个答案:

答案 0 :(得分:1)

mvn -f MyApp/pom.xml clean install -U

答案 1 :(得分:0)

假设在项目“ Y”的根目录中有一个文件夹“ X”,您必须在其中创建用于项目设置的shell脚本(运行maven命令,即自动完成构建过程)。 1.进入文件夹X,如下所示创建bash脚本:

#!/bin/bash
echo $PWD
cd $PWD
cd ../
echo $PWD
mvn clean install

答案 2 :(得分:0)

你可以写一个 .sh 文件,然后你可以提到 maven 命令来执行你的测试用例,下面是相同的 shell 脚本,只需使用 linux 命令执行这个 .sh 文件:

#!/bin/bash

#--------
# $1 is the argument value to check.
# $2 is the argument flag.
#--------
check_is_argument_correct() {
    if [[ "$1" == *"-"* ]]; then
            echo "Invalid value of Argument $2, value is $1"
            exit 1
    elif [ -z "$1" ]; then
            echo "Empty value for Argument $2"
            exit 1
    fi
}

#---------------------------
# ENTRYPOINT
#---------------------------

project_location=''
tags='@tags'

# Loop through arguments and process them
for arg in "$@"
do
    case $arg in
        -l|--location)
        project_location="$2"
        check_is_argument_correct $project_location $1
        shift
        shift
        ;;
        -t|--tags)
        tags="$2"
        check_is_argument_correct $tags $1
        shift
        shift
        ;;
    esac
done

if [ -z "$project_location" ]
then
      echo '--location or -l argument is empty'
      exit
fi

cd $project_location

echo "Running Tests"
echo "Project Location: $project_location"
echo "TAGS: $tags"

mvn clean test -Dcucumber.options="--tags $tags"
exit