最小化jar依赖项大小 [英] Minimizing jar dependency sizes

查看:165
本文介绍了最小化jar依赖项大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的一个应用程序使用了几个第三方罐子。有时只使用整个50kB到1.7mB jar的一小部分 - 一个或两个函数调用或类。



减少jar大小的最佳方法是什么。我应该下载源代码并构建一个只需要我需要的类的jar吗?哪些现有工具可以帮助实现此功能的自动化(例如,我简要介绍了 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)等。所以他们只包含我需要的最小班级



编辑2:
手动或使用程序最小化jar如果库使用反射,那么proguard会更复杂。
注入google guice用proguard混淆后不再起作用了



cletus对另一篇文章的回答非常好如何确定Java程序使用哪些类?

解决方案

Proguard 将是一个选项。它可以消除未使用的类和方法。您也可以使用它进行混淆,这可以进一步减小最终jar的大小。请注意,除非注意保持受影响的类别不被混淆,否则按名称加载类可能会中断。



我发现Proguard非常有效 - 可能有点神秘从一开始就明白。但我没有任何相似的经验可以提供比较。


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.

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/)?

Thank you

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

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

The answer by cletus on another post is very good How to determine which classes are used by a Java program?

解决方案

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.

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依赖项大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆