Follow below steps
1) Start the Terminal app.
2) Open bash profile -
$ vi ~/.bash_profile
2) Press key 'i' from keyboard to Insert text in bash profile
3) Insert Java and maven environments -
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
export PATH=$JAVA_HOME:$PATH
4) Press key 'Esc'
4) Press key ':wq!' to save and quit bash profile
5) Now run source command to refresh
source ~/.bash_profile
6) Verify Java and Maven works fine
Run command - echo $JAVA_HOME
The response should be something like- /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
Run command - mvn --version
The response should be something like-
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T04:57:37-07:00)
Maven home: /usr/local/apache-maven/apache-maven-3.3.3
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.1", arch: "x86_64", family: "mac"
7) Lastly, run maven project by cd into the Java project directory (enter your project path)-
cd /Users/[User]/Documents/workspace/Hybrid_TestNG
and run command mvn test
This should run the project successfully.
Remember, each time you start new session, you will have to source bash profile by running below command -
source ~/.bash_profile
---------------------------------------------------------------------------------