如何让Java应用程序尽可能小?
我正在构建一个必须嵌入 64KB 分区的 JApplet。到目前为止,我有足够的空间,但我想知道您是否可以给我一些关于如何使我的 jar 文件更小的好建议。我尽可能地重用代码并在编译时压缩 jar 文件。谢谢大家。
I am building a JApplet that has to be embedded on a 64KB partition. So far I have enough space, but I am wondering if you can give me some great tips on how to make my jar file smaller. I am reusing code as much as possible and compressing jar file when compiling. Thank you all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我肯定会做两件事:
(javac -g:none,或者 Ant/Maven 中的等效选项,无论您使用什么
编译)
Two things I would definitely do:
(javac -g:none, or equivalent option in Ant/Maven whatever you use
to compile)
由于大小将成为首要问题,因此您应该尽量避免外部依赖项/库。即使您需要它们,您也必须挑剔,可能会添加您的应用程序非常需要自定义的内容。因此请确保仅使用 Java 基础类。
Since size is going to be the prime concern, you should try avoiding as much as external dependencies/libraries. Even if you require them, you have to be picky, probably go and add which ever is very much custom required to your application. And thus make sure only Java Foundation classes are used.
阅读 Proguard 的示例。它具有缩小字节码大小的标志。另请查看这篇文章。
Read the examples for Proguard. It has flags that shrink the size of your bytecode. Take a look at this article as well.