Reputation: 219
I have a Java project that contains many very large source files and it compiles fine in Eclipse, however it will not compile with javac from the command line or within Ant.
When I try to compile it from the command with javac (or using Ant) I get a StackOverflow Exception:
[javac] java.lang.StackOverflowError
[javac] at com.sun.tools.javac.jvm.Gen.genCond(Gen.java:786)
[javac] at com.sun.tools.javac.jvm.Gen.genCond(Gen.java:739)
[javac] at com.sun.tools.javac.jvm.Gen.visitBinary(Gen.java:1841)
[javac] at com.sun.tools.javac.tree.Tree$Binary.accept(Tree.java:926)
[javac] at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:806)
[javac] at com.sun.tools.javac.jvm.Gen.genCond(Gen.java:786)
...
...
...
I have tried passing a number of arguments to the JVM such as -Xss, -Xmx, -Xoss etc both on the command line and in the Ant javac task but I always get the same error.
From what I have read, it seems that the Eclipse IDE has a compiler that is different to the Sun JDK. Is there a way to get the JDK to compile in a similar way to Eclipse?
Thanks, Stef
This is odd, but I have found that I can compile the code with JDK 1.6.
This isn't solving my problem because the code is used as a lib by another project and it complains and compiled version numbers as JDK 1.5 is the project standard at the moment (and will be for another few months).
Does anyone know what has changed in 1.6 and is it possible to apply those changes to 1.5 by flags?
Upvotes: 3
Views: 1925
Reputation: 719307
When you are running the "javac" command from the commandline, JVM parameters need to be specified using the "-J" option. For example; -J-Xms48m
sets the initial heap size.
This is documented in the javac(1) manual page.
If you are getting StackOverflowError
s, the option you should be tweaking is the thread stack size; e.g. -J-Xss5m
.
This is odd, but I have found that I can compile the code with JDK 1.6.
I expect that the explanation is one of the following:
One possible bug is https://bugs.java.com/bugdatabase/view_bug?bug_id=6273455
EDIT
... and is it possible to apply those changes to 1.5 by flags?
Assuming you mean flags to enable the compiler bug fix, the answer is most likely No. Indeed, if it is the bug above, then it looks like upgrading to the last JDK 1.5 patch release won't help either. However, there are two possible solutions:
The bug report above gives a possible workaround that entails changing the source code that is triggering the bug. But first you will need to confirm that this is the bug that is causing the problem, and identify the offending source code files.
It may be possible to compile your production code using the Sun JDK 1.6 compiler with the flags -source 1.5 -target 1.5
.
Upvotes: 3
Reputation: 308968
You should be able to tell Eclipse to use the same JDK that your command shell sees.
I believe the Eclipse JDK is from IBM, so that might explain the difference.
Upvotes: 0
Reputation: 75406
You may have to give the compiler LOTS of memory, when this happens (or you may have hit a bug, hard to say). Also be certain that the javac is forked in a separate process, otherwise these options are just ignored.
Upvotes: 1