减少外部jar文件大小 [英] Reduce external jar file size

查看:179
本文介绍了减少外部jar文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Java项目开发了一个模块。该模块依赖于外部库( fastutil )。问题是, fastutil.jar 文件比整个项目本身重14倍(14 MB)。我只使用库中的一小部分类。该模块现已完成,未来任何人都不可能扩展它。有没有办法我只能将相关的类提取到一些 fastutil_small.jar ,以便其他人不必下载所有这些额外的重量?

I've developed a module for a Java project. The module depends on external library (fastutil). The problem is, the fastutil.jar file is a couple of times heavier than the whole project itself (14 MB). I only use a tiny subset of the classes from the library. The module is now finished, and no-one is likely to extend it in future. Is there a way I could extract only the relevant class to some fastutil_small.jar so that others don't have to download all this extra weight?

推荐答案

混淆工具,例如 ProGuard 通常提供从jar文件中删除未使用的类(甚至字段和方法)的功能。但是,你必须小心验证一切仍然有效,因为你可能正在使用reflecton来访问ProGuard无法分析的类或方法。

Obfuscation tools such as ProGuard usually provide a feature to remove unused classes (and even fields and methods) from the jar file. You have to be careful to verify everything still works, 'though, because you might be using reflecton to access classes or methods that ProGuard can't analyze.

你可以使用只有那个功能并且已经得到了相当多的保存

You can use only that feature and already get quite some saving

或者你可以将它与其他节省空间的混淆技术(例如类和方法重命名)相结合,以节省更多的空间更难调试的代价(你的堆栈跟踪将变得难以解析)。

Or you could combine it with other space-saving obfuscation techniques (such as class and method renaming) to save even more space at the cost of harder debugging (your stack traces will become harder to parse).

这篇关于减少外部jar文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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