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!

Try Out Code2care Dev Tools:


Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR -