开发者

Compiles in Eclipse but not with Javac from command line: StackOverFlow

开发者 https://www.devze.com 2023-01-04 19:09 出处:网络
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.

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.

F开发者_Python百科rom 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?


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 StackOverflowErrors, 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:

  • you are tickling a javac bug that has been fixed in JDK 1.6 or a later patch release of JDK 1.5,
  • javac in JDK 1.6 is less stack hungry, or
  • the default stack size for javac has been increased.

One possible bug is http://bugs.sun.com/bugdatabase/view_bug.do?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:

  1. 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.

  2. 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消