简体   繁体   English

在Eclipse中编译但不在命令行中使用Javac编译:StackOverFlow

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

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. 我有一个包含许多非常大的源文件的Java项目,它在Eclipse中编译得很好,但它不能从命令行或Ant中使用javac进行编译。

When I try to compile it from the command with javac (or using Ant) I get a StackOverflow Exception: 当我尝试使用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)
   ...
   ...
   ...

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. 我已经尝试在命令行和Ant javac任务中将一些参数传递给JVM,例如-Xss,-Xmx,-Xoss等,但我总是得到相同的错误。

From what I have read, it seems that the Eclipse IDE has a compiler that is different to the Sun JDK. 根据我的阅读,Eclipse IDE似乎有一个与Sun JDK不同的编译器。 Is there a way to get the JDK to compile in a similar way to Eclipse? 有没有办法让JDK以类似于Eclipse的方式编译?

Thanks, Stef 谢谢,Stef


This is odd, but I have found that I can compile the code with JDK 1.6. 这很奇怪,但我发现我可以使用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). 这不是解决我的问题,因为代码被另一个项目用作lib而且它抱怨和编译版本号,因为JDK 1.5目前是项目标准(并将持续几个月)。

Does anyone know what has changed in 1.6 and is it possible to apply those changes to 1.5 by flags? 有谁知道1.6中的变化,是否可以通过标志将这些变化应用于1.5?

When you are running the "javac" command from the commandline, JVM parameters need to be specified using the "-J" option. 从命令行运行“javac”命令时,需要使用“-J”选项指定JVM参数。 For example; 例如; -J-Xms48m sets the initial heap size. -J-Xms48m设置初始堆大小。

This is documented in the javac(1) manual page . 这在javac(1)手册页中有记录

If you are getting StackOverflowError s, the option you should be tweaking is the thread stack size; 如果你得到StackOverflowError ,你应该调整的选项是线程堆栈大小; eg -J-Xss5m . 例如-J-Xss5m

This is odd, but I have found that I can compile the code with JDK 1.6. 这很奇怪,但我发现我可以使用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 , 你正在发痒JDK 1.6 或JDK 1.5的后续补丁版本中已修复的javac错误,
  • javac in JDK 1.6 is less stack hungry, or JDK 1.6中的javac不那么堆栈,或者
  • the default stack size for javac has been increased. javac的默认堆栈大小已增加。

One possible bug is http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6273455 一个可能的错误是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? ......是否可以通过标志将这些更改应用于1.5?

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. 假设您指的是启用编译器错误修复的标志,答案很可能不是。实际上,如果它是上面的错误,那么看起来升级到最后一个JDK 1.5修补程序版本也无济于事。 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 . 可以使用带有标志-source 1.5 -target 1.5的Sun JDK 1.6编译器编译生产代码。

You may have to give the compiler LOTS of memory, when this happens (or you may have hit a bug, hard to say). 当发生这种情况时,你可能不得不给编译器提供大量内存(或者你可能遇到了一个bug,很难说)。 Also be certain that the javac is forked in a separate process, otherwise these options are just ignored. 还要确保javac是在一个单独的进程中分叉的 ,否则这些选项只会被忽略。

You should be able to tell Eclipse to use the same JDK that your command shell sees. 您应该能够告诉Eclipse使用命令shell看到的相同JDK。

I believe the Eclipse JDK is from IBM, so that might explain the difference. 我相信Eclipse JDK来自IBM,所以这可能解释了它的不同之处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM