为什么eclipse会编译shell javac或mvn会产生错误的文件:代码太大? [英] Why eclipse compiles a file that shell javac or mvn produces an error: code too large?
问题描述
环境:
- Eclipse luna
- maven 3.2。 3
- java 7
我见过问题,但我不明白的是为什么eclipse可以编译此文件,而我们却无法
I've seen questions like this but what I don't understand is why eclipse can compile this file and we aren't able to do it through the shell.
我也知道这个文件必须是属性文件,但这是我在项目中找到的。
I also know that this file it would have to be a properties file but it is what I found in a project.
Eclipse编译文件并创建字节码Messeges.class,但是javac和mvn都不能这样做,因为错误:代码太大。
Eclipse compiles de file and create the bytecode Messeges.class, but neither javac nor mvn could do that because the error: code too large.
此文件Messages.java是具有3232行的枚举,并用作将其加载到内存中的属性。它具有大约3100个不同的元素。
This file Messages.java is an enum that has 3232 lines and is used as a properties to load al this in memory. It has about 3100 different elements.
Messages.java
public enum Messages {
MENU_MANAGEMENT("Management menu"),
...3100..
MENU_OTHER("Other");
private String name;
private Messages(String name) {
this.name = name;
}
...
}
错误
$javac Messages.java
Messages.java:11: error: code too large
MENU_MANAGEMENT("Management menu"),
^
1 error
eclipse如何或为什么编译它?我不明白日食如何做到??
推荐答案
当枚举常量的数量大于2000时,eclipse会生成综合方法来解决代码大小限制。
When the number of enum constants is higher than 2000, eclipse generates synthetic methods to work around the code size limit.
请参见 https://bugs.eclipse.org/bugs/show_bug.cgi?id=331334
BTW :在您的Maven构建中切换为ecj并不是长期解决方案:该解决方案仅在Java 9之前有效,因为自 https://bugs.java.com/view_bug.do?bug_id=JDK-8157181
BTW: Switching to ecj as compiler in your maven build isn't a long term solution either: This solution only works before Java 9, because initializing a final field outside initialization methods is disallowed since https://bugs.java.com/view_bug.do?bug_id=JDK-8157181
这篇关于为什么eclipse会编译shell javac或mvn会产生错误的文件:代码太大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!