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

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

问题描述

我为 Java 项目开发了一个模块.该模块依赖于外部库 (fastutil).问题是,fastutil.jar 文件比整个项目本身(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 文件中删除未使用的类(甚至字段和方法)的功能.不过,您必须小心验证一切是否仍然有效,因为您可能正在使用反射来访问 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天全站免登陆