javac错误“代码太大"? [英] 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.静态初始化在单个方法中完成(参见 link)
您可以尝试从文件中加载数组数据.
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错误“代码太大"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!