MMP
MMP

Reputation: 556

Cannot access mvn command from bash script

I want to run the following script as:

bash ./scripts/startapp.sh

Here is the script:

#!/bin/bash
str=$HOSTNAME
PREV_IFS=$IFS
IFS=. components=(${str})
ORIGINAL_DIRECTORY=`pwd`
REP_DIRECTORY=$ORIGINAL_DIRECTORY/src/main/resources
for part in "${components[@]}"
do
  PATH=$REP_DIRECTORY/"$part"
  REP_DIRECTORY=$PATH
done
IFS=$PREV_IFS
CONFIG_PATH=$REP_DIRECTORY/application.yaml
# Below is the final command I want to run from the terminal
`SPRING_CONFIG_LOCATION=$CONFIG_PATH mvn spring-boot:run`

I am getting

mvn: command not found

Without starting the script, I can use mvn spring-boot:run without any problem.

Upvotes: 2

Views: 950

Answers (1)

carlspring
carlspring

Reputation: 32567

Make sure you have defined:

  • M2_HOME pointing to the base directory of your Maven installation

  • PATH must include $M2_HOME/bin

In your script you're overwriting the value of PATH on every iteration. You should change it to:

PATH=$PATH:$REP_DIRECTORY/"$part"

Upvotes: 2

Related Questions