At times Maven build fails with java.lang.OutOfMemory, while running or compiling the multiple projects. This hapens because Maven run out of available system memory. You can solve this by increasing the memory available to Maven, the environment variable MAVEN_OPTS should be set to the value -Xmx1024m -XX:MaxPermSize=128m, or more depending on the amount of memory you have available on your machine.

Using The Bash Shell

Command to increase the memory using the bash shell. Add following in your ~/.bash_profile to have it available in all your sessions.
export MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=128m

Using This csh File

Equivalent command in csh. Add this to your ~/.cshrc file to have this setting available in all your sessions.
setenv MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=128m

Using Windows Command Prompt

Finally, if you are using Windows, then this command can be used from the command prompt.
set MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=128m We can make this variable permanent on Windows, use the Control Panel -> System dialog. Select the Advanced tab and click Environment Variables. Under the System Variables table, click New. Type MAVEN_OPTS for the Variable name and -Xmx1024m -XX:MaxPermSize=128m for the Variable value.