Sunday, June 26, 2011

STS with Maven - java.lang.OutOfMemoryError: Java heap space

I've recently started using SpringSource Tool Suite (STS) for a large Flex on Java project, In the recent configuration I used eclipse to code and launched Maven using command line. STS provides a built in Maven launcher which really makes more sense to use (STS use m2eclipse to fully integrate maven with eclipse). The only problem is that once I tried to run mvn clean install I ran into the good old heap space issue:

java.lang.OutOfMemoryError: Java heap space
at org.aspectj.weaver.bcel.LazyClassGen.toLongString(
at org.aspectj.weaver.bcel.BcelWeaver.weave(
at org.aspectj.weaver.bcel.BcelWeaver.weaveWithoutDump(
at org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(
at org.aspectj.weaver.bcel.BcelWeaver.weave(
at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.weaveQueuedEntries(
at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.queueForWeaving(
at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.afterProcessing(
at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$after$org_aspectj_ajdt_internal_compiler_CompilerAdapter$5$6b855184(CompilerAdapter.aj:98)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(
at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(
at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(
at org.codehaus.mojo.aspectj.AbstractAjcCompiler.execute(
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(
at org.apache.maven.DefaultMaven.doExecute(

The solution obviously is to increase the maximum heap size which is represented by the JVM -Xmx argument. Now there are a number of places you can find this argument (STS.ini is one of them) , but here's the one place I found that really makes the difference.

  • Goto the 'Run Configurations' popup of the current maven run you are trying to use (can be accesed by right clicking your project and selecting 'Run As')
  • Select your current run under 'Maven Build' in the tree
  • Select the the JVM tab and add your requested -Xmx settings (I chose -Xmx512m)
  • Press 'Apply' and 'Run'

You should now be able to run your Maven project.


Javin @ java hashmap tutorial said...

Maven require lot of memory if you are using xmlbeans etc. by the way here is how I solve 2 solution of java.lang.outofmemoryerror java heap space in my application.

Abu_Arafa said...

Many Thanks, It's working fine for me