java 减少jar文件大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7810896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reducing jar file size?
提问by user1001630
Is there a good app to reduce jar file size by eliminating redundant classes/methods/constant pool elements? (i.e. not reachable from a fixed set of entry points, assuming no reflection)
有没有一个好的应用程序可以通过消除冗余的类/方法/常量池元素来减少 jar 文件的大小?(即无法从一组固定的入口点到达,假设没有反射)
I'm tired of pulling in bloated libraries when I'm just using a couple of methods from them.
当我只使用它们中的几种方法时,我已经厌倦了引入臃肿的库。
(I'm not talking about small "local" optimizations like making names smaller. I'm thinking more of something that does global analysis to figure out which classes/methods/variables are used, given a set of entry points (including reflective entry points), and removes everything that is not used.
(我不是在谈论像使名称更小这样的小型“本地”优化。我想更多的是进行全局分析以确定使用哪些类/方法/变量,给定一组入口点(包括反射入口)点),并删除所有未使用的内容。
My webapp is like, 45MB, mostly due to 30-odd libraries, and I'm pretty sure I'm using only a small fraction of each library.
我的 webapp 大概是 45MB,主要是因为有 30 多个库,而且我很确定我只使用了每个库的一小部分。
回答by om-nom-nom
Yes, there is one - Proguard.
是的,有一个 - Proguard。
ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using short meaningless names. Finally, it preverifies the processed code for Java 6 or for Java Micro Edition.
ProGuard 是一个免费的 Java 类文件压缩器、优化器、混淆器和预验证器。它检测并删除未使用的类、字段、方法和属性。它优化字节码并删除未使用的指令。它使用无意义的简短名称重命名剩余的类、字段和方法。最后,它为 Java 6 或 Java Micro Edition 预验证已处理的代码。
回答by Grodriguez
回答by Hugo Rocha
Just another nice trick, usually using the unnamed package, which is deleting the name (< default> will appear), also decreases the jar size.
只是另一个不错的技巧,通常使用未命名的包,即删除名称(< default> 将出现),也减少了 jar 大小。
In my case my jar went from 24,243 bytes to 23,946. Yeah not a big deal but still a cool trick i think.
就我而言,我的 jar 从 24,243 字节变为 23,946。是的,没什么大不了的,但我认为仍然是一个很酷的技巧。
From efficient MIDP programming:
从高效的 MIDP 编程:
"Use the 'unnamed package' – placing your MIDlet classes all in the same named package only increases the size of your MIDlet's JAR file; reserve the package statement for libraries"http://carfield.com.hk/document/java/articles/Efficient_MIDP_Programming.pdf
“使用‘未命名包’——将所有 MIDlet 类放在同一个命名包中只会增加 MIDlet 的 JAR 文件的大小;为库保留包声明” http://carfield.com.hk/document/java/articles /Efficient_MIDP_Programming.pdf