在 Eclipse 中编译,但不能从命令行使用 Javac:StackOverFlow
我有一个 Java 项目,其中包含许多非常大的源文件,它在 Eclipse 中编译得很好,但是它不能从命令行或 Ant 中使用 javac 进行编译。
当我尝试使用 javac (或使用 Ant)从命令编译它时,出现 StackOverflow 异常:
[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)
...
...
...
我尝试在命令行和在 Ant javac 任务中,但我总是遇到相同的错误。
据我了解,Eclipse IDE 的编译器似乎与 Sun JDK 不同。有没有办法让JDK以类似于Eclipse的方式编译?
谢谢, Stef
这很奇怪,但我发现我可以使用 JDK 1.6 编译代码。
这并不能解决我的问题,因为该代码被另一个项目用作库,并且它会抱怨并编译版本号,因为 JDK 1.5 是目前的项目标准(并且将持续几个月)。
有谁知道 1.6 中发生了什么变化,是否可以通过标志将这些更改应用到 1.5?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您从命令行运行“javac”命令时,需要使用“-J”选项指定 JVM 参数。例如;
-J-Xms48m
设置初始堆大小。这在 javac(1) 手册中进行了记录页面。
如果您遇到 StackOverflowError,您应该调整的选项是线程堆栈大小;例如
-J-Xss5m
。我希望解释是以下之一:
一个可能的错误是 https://bugs.java.com/bugdatabase/view_bug?bug_id= 6273455
编辑
假设您的意思是启用编译器错误修复的标志,答案很可能是否定的。事实上,如果是上面的错误,那么看起来升级到最新的 JDK 1.5 补丁版本也无济于事。但是,有两种可能的解决方案:
上面的错误报告提供了一种可能的解决方法,需要更改触发错误的源代码。但首先您需要确认这是导致问题的错误,并识别有问题的源代码文件。
可以使用带有标志
-source 1.5 -target 1.5
的 Sun JDK 1.6 编译器来编译生产代码。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
.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
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
.当发生这种情况时,您可能必须为编译器提供大量内存(或者您可能遇到了错误,很难说)。还要确保 javac 在单独的进程中分叉,否则这些选项将被忽略。
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.
您应该能够告诉 Eclipse 使用命令 shell 看到的相同 JDK。
我相信 Eclipse JDK 来自 IBM,因此这可以解释其中的差异。
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.