views:

170

answers:

2

Hi,

When I'm trying to build Apache FOP by ant on the command line, it complains:

    [javac] The system is out of resources.
[javac] Consult the following stack trace for details.
[javac] java.lang.OutOfMemoryError: Java heap space
[javac]     at com.sun.tools.javac.zip.ZipFileIndex.readBytes(ZipFileIndex.java:557)
[javac]     at com.sun.tools.javac.zip.ZipFileIndex.read(ZipFileIndex.java:511)
[javac]     at com.sun.tools.javac.util.DefaultFileManager$ZipFileIndexFileObject.read(DefaultFileManager.java:1629)
[javac]     at com.sun.tools.javac.util.DefaultFileManager$ZipFileIndexFileObject.openInputStream(DefaultFileManager.java:1549)
[javac]     at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:1844)
[javac]     at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1777)
[javac]     at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
[javac]     at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:758)
[javac]     at com.sun.tools.javac.jvm.ClassReader.loadClass(ClassReader.java:1951)
[javac]     at com.sun.tools.javac.comp.Resolve.loadClass(Resolve.java:842)
[javac]     at com.sun.tools.javac.comp.Resolve.findIdentInPackage(Resolve.java:1011)
[javac]     at com.sun.tools.javac.comp.Attr.selectSym(Attr.java:1921)
[javac]     at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:1835)
[javac]     at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1522)
[javac]     at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:360)
[javac]     at com.sun.tools.javac.comp.Attr.attribType(Attr.java:390)
[javac]     at com.sun.tools.javac.comp.MemberEnter.attribImportType(MemberEnter.java:681)
[javac]     at com.sun.tools.javac.comp.MemberEnter.visitImport(MemberEnter.java:545)
[javac]     at com.sun.tools.javac.tree.JCTree$JCImport.accept(JCTree.java:495)
[javac]     at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:387)
[javac]     at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:399)
[javac]     at com.sun.tools.javac.comp.MemberEnter.visitTopLevel(MemberEnter.java:512)
[javac]     at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:446)
[javac]     at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:387)
[javac]     at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:819)
[javac]     at com.sun.tools.javac.code.Symbol.complete(Symbol.java:386)
[javac]     at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:758)
[javac]     at com.sun.tools.javac.comp.Enter.complete(Enter.java:451)
[javac]     at com.sun.tools.javac.comp.Enter.main(Enter.java:429)
[javac]     at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:819)
[javac]     at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
[javac]     at com.sun.tools.javac.main.Main.compile(Main.java:353)

I don't understand. I have 4 GB RAM, how can the system run out of resources?

Best regards, Niels

A: 

You need to give more memory to your JVM. e.g. the below allocates 512Mb to the JVM.

javac -Xmx512m ...

The Java virtual machine runs with a fixed maximum memory size. For memory-intensive operations you need to increase this appropriately. -Xmx specifies the maximum amount of memory the JVM will take. -Xms specifies the amount of memory the JVM allocates on start-up.

There's a nice summary of options here.

Note: Given the above occurs via Ant, you may need to increase the memory available to Ant (e.g. set ANT_OPTS=-Xms256M -Xmx512M), and/or the memory available to your javac process if that's being forked as a separate executable.

Brian Agnew
Thanks! export ANT_OPTS="-Xms1024M -Xmx1024M" finally worked.
Polybos
+1  A: 

the size of your system memory is only half of the story, the JVM allocates a memory chunck as a heap space when it starts up. the java compiler as a java application has only this amount of memory to work with

you can set the heap size for the java compiler yourself with this option

javac     -J-Xms<size>m 

see the complete switches sets here

Alon