You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CMD执行mvn -version报错:找不到主类,求解决方案

Fixing "Could not find or load main class" Error for 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 /bin suffix at the end).
    • If it doesn't exist, click "New", set the variable name to MAVEN_HOME and variable value to the root path above.

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 Path variable and edit it.
  • Look for any entry pointing directly to C:\Users\acer\Desktop\apache-maven-3.5.3\bin and 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_OPTS entry.
  • If it exists, make sure its value only contains JVM arguments (like -Xmx512m or -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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:24:49