Minimizing jar dependency sizes(最小化 jar 依赖大小)
问题描述
我编写的一个应用程序使用了几个第三方 jar.有时只使用了整个 50kB 到 1.7mB jar 中的一小部分——一个或两个函数调用或类.
an application I have written uses several third party jars. Sometimes only a small portion of the entire 50kB to 1.7mB jar is used - one or two function calls or classes.
减小罐子尺寸的最佳方法是什么.我应该下载源代码并用我需要的类构建一个 jar 吗?哪些现有工具可以帮助实现这一点(例如,我简要地查看了 http://code.google.com/p/jarjar/)?
What is the best way to reduce the jar sizes. Should I download the sources and build a jar with just the classes I need? What existing tools can help automate this (ex I briefly looked at http://code.google.com/p/jarjar/)?
谢谢
编辑 1:我想减小我的第三方官方"罐子的大小,如 swingx-1.6.jar (1.4 MB)、set-3.6 (1.7 MB) glazedlists-1.8.jar (820kB) 等,以便它们只包含我需要的最低限度的课程
Edit 1: I would like to lower the size of my third party 'official' jars like swingx-1.6.jar (1.4 MB), set-3.6 (1.7 MB) glazedlists-1.8.jar (820kB) , etc. so that they only contain the bare minimum classes I need
编辑 2:如果库使用反射,则手动或使用 proguard 之类的程序最小化 jar 会更加复杂.使用 google guice 注入不再起作用用proguard混淆后
Edit 2: Minimizing a jar by hand or by using a program like proguard is further complicated if the library uses reflection. Injection with google guice does not work anymore after obfuscation with proguard
cletus 在另一篇文章中的回答非常好 如何判断Java程序使用了哪些类?
The answer by cletus on another post is very good How to determine which classes are used by a Java program?
推荐答案
Proguard 将是一个选项.它可以消除未使用的类和方法.您还可以使用它来混淆,这可以进一步减小最终 jar 的大小.请注意,除非注意保持受影响的类不被混淆,否则按名称加载类可能会中断.
Proguard would be an option. It can eliminate unused classes and methods. You can also use it to obfuscate, which can further reduce the size of your final jar. Be aware that class loading by name is liable to break unless care is taken to keep the affected classes unobfuscated.
我发现 Proguard 非常有效 - 一开始可能有点难以理解.但是我没有任何类似的经验来提供比较.
I've found Proguard quite effective - can be a bit cryptic to understand at the outset. But I don't have any experience with similar to offer a comparison.
这篇关于最小化 jar 依赖大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:最小化 jar 依赖大小


基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01