Maven : java.lang.ClassNotFoundException: Xmx512m

localhost:~ code2care$ mvn --version
Exception in thread "main" java.lang.NoClassDefFoundError: Xmx512m
Caused by: java.lang.ClassNotFoundException: Xmx512m
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(

If you get the above stack trace when you run some maven command in Terminal (Mac OS or Linux) or on Command Prompt (Windows OS) then its because you have not set the environment variable MAVEN_OPTS correctly, to fix this issue,

On macOS / Linux:
  1. Open terminal
  2. Type the following command: export MAVEN_OPTS=Xmx512m
On Windows:
  1. Right click on My Computer icon → Properties → Advance System Settings → Environment Variables → New
  2. Check the value of Variable Name: MAVEN_OPTS
  3. You must correct Variable Value it by adding a hyphen: -Xmx512m
  4. Click OK.

MAVEN_OPTS is used to set the maven heap size it can be set as -Xmx256m, -Xmx512m, -Xmx1024m, -Xmx2048m and so on depending upon your project memory requirement!

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap