Reached the 65536 bytes limit

家住魔仙堡 提交于 2019-12-24 09:48:07

问题


I'm about to do some work on this hideous old java web app a friend on mine inherited a while ago.

After I've set up tomcat, imported project and all that to my eclipse workspace I get this error that a method in the servlet exceeds the 65536 bytes limit.

The method may very well exceed that limit, it's several thousand loc. But the thing is, I've worked on this app before without getting this error, and according to the commit logs, no code has been added to the servlet since.

Can it be because this time I'm working on a macbook? Last time I worked on the app I used a HP desktop with ubuntu. Different java version, cpu architecture? Is this even possible?

Is there anything I can do except refactor the code?


回答1:


Is there anything I can do except refactor the code?

No. Refactor the code. No method should be that long. Ever. Write small methods!

Seriously: any IDE there is will guide you through the refactoring, but it needs to be done. You might also want to read Refactoring: Improving the Design of Existing Code for guidance.




回答2:


What cpu you are using shouldn't matter. It's most likely that the compiler that you now are using is producing another output (that exceeds the limit).

I would definately refactor, but you could try to switch to the same compiler as you used the last time you compiled the code.




回答3:


If the code is generated by a JSP page it could be exceeding the 64k method limit. Some web containers like Weblogic will actually work around this problem for you. Tomcat won't, perhaps you were using a different web container before? To workaround the issue this page suggests changing your static includes like this:

<%@ include file="test.jsp" %>

To dynamic includes like this:

<jsp:include page="test.jsp" /> 

Update: since you're dealing with a servlet you're probably out of luck. This is a JVM specification limitation, see Why does Java limit the size of a method to 65535 byte? I don't believe you'll find a compiler that works around it. You might have some luck with ProGuard to minimize the compiled size.




回答4:


One thing which can make a method smaller is to turn off debugging. When debugging is on, each line (with code) has a statement which labels the line.



来源:https://stackoverflow.com/questions/5908436/reached-the-65536-bytes-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!