For me I had a AdoptOpenJDK 8 installed, instead of SE JDK 8. For which it was not able to recognize JAVA_HOME or mvn commands.
Check your java_home
/usr/libexec/java_home -V
and use JAVA SE SDK if it is different.
Then follow the above steps to install maven and check again