Maven : java.lang.ClassNotFoundException: Xmx512m


localhost:~ code2care$ mvn --version
Exception in thread "main" java.lang.NoClassDefFoundError: Xmx512m
Caused by: java.lang.ClassNotFoundException: Xmx512m
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

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