javac的错误" code太大"? [英] 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?
答:十米台的回答没有的伎俩。让我感动的字节数组到一个单独的类,它编译罚款。谢谢!
Answer: Shimi's answer did the trick. I moved the byte array out to a separate class and it compiled fine. Thanks!
推荐答案
在Java方法是在字节code限制在64K。静态初始化在一个单一的方法进行(见链接)
你可以尝试从文件加载阵列的数据。
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的错误" code太大"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!