When configuring maven on the mac system, after completing the previous configuration, after entering mvn -version, the following error appears:
-
The JAVA_HOME environment variable is not defined correctly
-
This environment variable is needed to run this program
-
The solution is as follows:
1. To query the current java version, enter: java -version in the terminal
Display: java version "1.8.0_311"
2. Enter vim ~/.bash_profile in the terminal again and press Enter, then press i to enter editing mode
显示:JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/
3. Change 1.8.0_101 in the above line to 1.8.0_311, then press esc to exit editing, and enter: wq to save.
4. Enter source ~/.bash_profile in the terminal again and press Enter. Enter mvn -version, press Enter, and the maven version information will be displayed normally.