javac error“code too large”? [英] javac error "code too large"?
问题描述
我有一个单元测试,我静态定义了一个相当大的字节数组(超过8000字节)作为文件的字节数据,我不想每次运行我的单元测试时读取。
I have a unit test where I have statically defined a quite large byte array (over 8000 bytes) as the byte data of a file I don't want to read every time I run my unit test.
private static final byte[] FILE_DATA = new byte[] {
12,-2,123,................
}
这在Eclipse中编译良好,通过Ant脚本我得到以下错误:
This compiles fine within Eclipse, but when compiling via Ant script I get the following error:
[javac] C:\workspace\CCUnitTest\src\UnitTest.java:72: code too large
[javac] private static final byte[] FILE_DATA = new byte[] {
[javac] ^
任何想法为什么以及如何避免这种情况?
Any ideas why and how I can avoid this?
回答:Shimi的回答做了一个诀窍。我把字节数组移出到一个单独的类,它编译正常。谢谢!
Answer: Shimi's answer did the trick. I moved the byte array out to a separate class and it compiled fine. Thanks!
推荐答案
Java中的方法限制为64k字节码。静态初始化是通过单一方法完成的(请参阅链接)$ b $bÚ
您可以尝试从文件加载数组数据。
Methods in Java are restricted to 64k in the byte code. Static initializations are done in a single method (see link)
You may try to load the array data from a file.
这篇关于javac error“code too large”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!