Maven : java.lang.ClassNotFoundException: Xmx512m

Posted on : Mon, 4th May 15 12:45 pm GMT

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 enviroment variable MAVEN_OPTS correctly, to fix this issue,

  1. On Mac OS X / Linux :

    • Open terminal
    • Type the following command : export MAVEN_OPTS=Xmx512m
  2. On WIndows :

    • Right click on My Computer icon -> Properties -> Advance System Settings -> Environment Variables -> New
    • Check the value of Variable Name : MAVEN_OPTS
    • You must correct Variable Value it by adding a hyphen : -Xmx512m
    • 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!

We are operating with limited resources due to COVID-19 - Stay Safe!

We stands in support of racial equality!

Follow us : Facebook - Twitter