how to run maven project using sh file in linux

For windows system I used the batch file with below commands:

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

Its working fine in windows.

But I want to use run Maven project from Linux system using sh file.

Please let me know the sh commands, which are equal for the above windows batch commands.

Thanks.

Upvotes: 2

Views: 11696

Answers (3)

Sudheer Singh
Sudheer Singh

Reputation: 664

You can write a .sh file and in that, you can mention the maven command to execute your test cases, below are the shell script for the same, just execute this .sh file using linux command:

#!/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

Upvotes: 0

GoingGeek
GoingGeek

Reputation: 71

Assuming in the root of your project 'Y' you have a folder 'X', where you have to create a shell script for project setup(running maven commands i.e automating your build process). 1. Go inside folder X, create bash script as follows:

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

Upvotes: 3

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

?

Upvotes: 1

Related Questions