CMD执行mvn -version报错:找不到主类,求解决方案
mvn -version Hey there, let's get this Maven issue sorted out for you. That error message usually points to a misconfigured environment variable—here's how to fix it step by step:
Step 1: Correct your MAVEN_HOME environment variable
The most common culprit here is setting MAVEN_HOME to the bin directory instead of Maven's root folder.
- Right-click "This PC" → Properties → Advanced System Settings → Environment Variables.
- Under "System Variables", look for
MAVEN_HOME:- If it exists, edit it to point to Maven's root path:
C:\Users\acer\Desktop\apache-maven-3.5.3(remove the/binsuffix at the end). - If it doesn't exist, click "New", set the variable name to
MAVEN_HOMEand variable value to the root path above.
- If it exists, edit it to point to Maven's root path:
Step 2: Update your PATH variable
Your PATH should reference the bin directory using the MAVEN_HOME variable, not a hardcoded path:
- In the same "System Variables" section, find the
Pathvariable and edit it. - Look for any entry pointing directly to
C:\Users\acer\Desktop\apache-maven-3.5.3\binand replace it with%MAVEN_HOME%\bin. If there's no such entry, add this new path.
Step 3: Check for problematic MAVEN_OPTS configuration
Occasionally, a misconfigured MAVEN_OPTS variable can cause this error:
- In "System Variables", check if there's a
MAVEN_OPTSentry. - If it exists, make sure its value only contains JVM arguments (like
-Xmx512mor-XX:MaxPermSize=256m). Remove any incorrect paths or classpath references you might have added here.
Step 4: Verify the fix
Important: Close all open Command Prompt windows first—environment variable changes don't take effect in existing sessions. Open a new CMD window, then run:
mvn -version
This should now work if the variables are set correctly.
If you're still running into issues, double-check that:
- There are no typos in your path values (extra spaces, missing slashes, etc.).
- Your Maven installation is intact (try re-downloading the Maven archive and extracting it again if you suspect corruption).
Let me know if you hit any snags along the way!
内容的提问来源于stack exchange,提问作者Jones Kevin

