确定使用的库以减少JAR文件的大小 [英] Determine used libraries to reduce JAR file size

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

问题描述

我在某些程序中使用HtmlUnit,但始终遇到的问题是,每当使用HtmlUnit时,都必须添加从HtmlUnit网站下载的所有文件(库),因此我得到的jar文件始终为10 mb.

I am using HtmlUnit in some programs and I always have the problem that whenever I use it, I have to add all the files (libraries) that I downloaded from HtmlUnit website so the jar file that I get is always 10 mb.

这些是我添加的文件:

但是在我的大多数程序中,我仅包含以下内容:

But in most of my programs I only include this:

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.RefreshHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.*;

我通常只使用WebClient和HtmlElements(HtmlForm,HtmlTable等),所以我感到很奇怪,因为我需要它们全部.

I usually only use WebClient and HtmlElements (HtmlForm, HtmlTable, etc.), so i find it strange that I need all of them.

我的问题是,是否可以减少包含的库的数量,或者更好些,如何确定完全不使用包含的库.

My question is if I could reduce the number of libraries included, or maybe better, how can I determine which libraries that I include are not being used at all.

推荐答案

您是否真的要检查所有添加的库的所有类(是否需要)?

Do you really want to check all classes of all added libraries if they are needed or not?

恕我直言,这是程序工作. ProGuard .

IMHO this is a job for program. One popular open source program for doing so is ProGuard.

通常,ProGuard被称为混淆器(重命名类文件中的所有内容,因此很难理解反编译的类),但是在使用参数 -dontobfuscate 时,可以将其使用而不会混淆.另外,我建议您也使用 -dontoptimize 参数.

Generally ProGuard is known as obfuscator (rename everything in the class files so that understanding the decompiled classes is difficult) but it can be used without obfuscation when using the parameters -dontobfuscate. Additionally I suggest you to use the -dontoptimize parameter as well.

如果您在胖胖的JAR上运行ProGuard,您将得到一个小得多的JAR.

If you run ProGuard on you big fat JAR you will get a much smaller one.

如果您有兴趣,我可以发布一小部分ant构建文件,其中显示了如何配置和调用ProGuard.

If you are interested I could post a small part of an ant build file that shows how to configure and call ProGuard.

这篇关于确定使用的库以减少JAR文件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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