Maven : java.lang.ClassNotFoundException: Xmx512m


Posted on : Mon, 4th May 15 12:45 pm UTC
100+ votes

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 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.


Advertisements





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!

Code2care's mission is to share varied knowledge in technical and non-technical areas gathered during day-to-day learnings and development activities so that our visitors can leverage this portal to find solutions to their queries without re-inventing the wheel. Technical posts include Learnings, Tutorials, Video Tutorials, Code Snippets, Tips-n-tricks.

Follow us : Facebook - Twitter - Google +