开发者

Reached the 65536 bytes limit

开发者 https://www.devze.com 2023-03-03 01:47 出处:网络
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 t

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 worke开发者_运维技巧d 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?


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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消