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 java.io.BufferedWriter.(BufferedWriter.java:87)
at java.io.BufferedWriter.(BufferedWriter.java:70)
at java.io.PrintStream.init(PrintStream.java:83)
at java.io.PrintStream.(PrintStream.java:100)
at java.io.PrintStream.(PrintStream.java:62)
at org.aspectj.weaver.bcel.LazyClassGen.toLongString(LazyClassGen.java:764)
at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1837)
at org.aspectj.weaver.bcel.BcelWeaver.weaveWithoutDump(BcelWeaver.java:1755)
at org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1515)
at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1322)
at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.weaveQueuedEntries(AjPipeliningCompilerAdapter.java:435)
at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.queueForWeaving(AjPipeliningCompilerAdapter.java:371)
at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.afterProcessing(AjPipeliningCompilerAdapter.java:358)
at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$after$org_aspectj_ajdt_internal_compiler_CompilerAdapter$5$6b855184(CompilerAdapter.aj:98)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:652)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:392)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:1007)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:268)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:182)
at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112)
at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
at org.aspectj.tools.ajc.Main.run(Main.java:355)
at org.aspectj.tools.ajc.Main.runMain(Main.java:234)
at org.codehaus.mojo.aspectj.AbstractAjcCompiler.execute(AbstractAjcCompiler.java:378)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)

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.

2 comments:

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