This happened to me when I tried to upgrade to new Maven version.
Below are the steps you should follow when setting up Maven on Windows.
If something is missing, the above error will trigger (most probably the 2nd or 3rd step may be missing for mentioned error).
Step 1:
First, download(Apache Maven download link:
https://maven.apache.org) and extract it to C:\Program Files
Step 2:
Go to Environment Variables
and Define below varibles in System variables

M2_HOME - C:\Program Files\apache-maven-3.3.9
MAVEN_HOME -
C:\Program Files\apache-maven-3.3.9
Step 3:
Make sure to add the maven bin
file to Path varible in System variable

C:\Program Files\apache-maven-3.3.9\bin
Step 4:
Once you are done with configurations, make sure to restart the project.
Step 5:
Check whether the Maven is configured successfully using below command
mvn -version
