An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options
-Xmx512M, this will immediately solve your OutOfMemoryError.
In Eclipse :
go to Run --> Run Configurations --> then select the project under maven build --> then select the tab "JRE" --> then enter
This should increase the memory heap for all the builds/projects. The above memory size is 1 GB.