已达到 65536 字节限制
我即将对这个可怕的旧 java web 应用程序做一些工作,我的一个朋友不久前继承了这个应用程序。
在我设置 tomcat、导入项目和所有这些到我的 eclipse 工作区后,我收到此错误,指出 servlet 中的方法超出了 65536 字节限制。
该方法很可能会超出该限制,它是几千个位置。但问题是,我之前曾使用过这个应用程序,但没有遇到此错误,并且根据提交日志,此后没有向 servlet 添加任何代码。
难道是因为我这次用的是MacBook?上次我开发该应用程序时,我使用了装有 ubuntu 的 HP 桌面。不同的java版本,cpu架构?这可能吗?
除了重构代码我还能做什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,重构代码。任何方法都不应该那么长。曾经。 编写小方法!
说真的:任何 IDE 都有将指导您完成重构,但这需要完成。您可能还想阅读重构:改进现有代码的设计以获取指导。
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.
你用什么CPU应该不重要。您现在使用的编译器很可能正在生成另一个输出(超出限制)。
我肯定会重构,但您可以尝试切换到上次编译代码时使用的同一编译器。
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.
如果代码是由 JSP 页面生成的,则可能会超出 64k 方法限制。一些 Web 容器(例如 Weblogic)实际上可以为您解决这个问题。 Tomcat 不会,也许您之前使用过不同的 Web 容器?要解决此问题,此页面建议更改您的静态包含如下:
动态包含如下:
更新:因为您正在处理 servlet,所以您可能不走运。这是 JVM 规范限制,请参阅 为什么 Java 将方法的大小限制为 65535 字节? 我不相信您会找到一个可以解决这个问题的编译器。您可能会幸运地使用 ProGuard 来最小化编译大小。
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:
To dynamic includes like this:
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.