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

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

问题描述

有没有办法减少jar文件的大小?

Is there any way to reduce jar file size?

我想要一个减少未使用的依赖项的工具。

I want a tool that reduces the unused dependencies.

我使用maven进行依赖管理。

I use maven for dependency management.

任何帮助都将受到赞赏。

Any help will be appreciated.

推荐答案

JAR文件通常不包含Maven意义上的依赖项。所以你必须要谈论:

A JAR file doesn't normally contain dependencies in the Maven sense. So you must be talking about:


  • 一个WAR或EAR或类似文件,

  • 一个如此通过组合大量JAR文件生成的调用UberJAR文件;例如使用Maven shade插件,或

  • 依赖项,其粒度比Maven模块更精细。

在前两种情况下,您可以通过在依赖项规范或war或shade插件构建描述符中排除它们来阻止名义上依赖的JAR。 IIRC,shade插件还允许您排除特定的包和类。

In the first two cases, you can keep out nominally dependent JARs by excluding them, either in the dependency specification, or in the war or shade plugin build descriptor. IIRC, the shade plugin also allows you to exclude specific packages and classes.

最后一个可能需要一个单独的工具来后处理JAR文件。摆脱未使用的类是混淆器可以做的事情。但是,您需要注意不要删除反射使用的类或类名;例如通过DI / IoC框架或AOP框架。

The last may require a separate tool to post-process the JAR file. Getting rid of unused classes is the kind of thing that an obfuscator can do. However, you need to be careful not to eliminate classes or class names that are used reflectively; e.g. by a DI / IoC framework or an AOP framework.

(一般来说,这种工具试图通过分析.class文件外部引用所暗示的依赖关系来确定使用哪些类.DI / IoC / AOP等等引入.class文件结构中不明显的其他类型的依赖。)

(Generally speaking, this kind of tool tries to figure out what classes are used by analysing the dependencies implied by .class file external references. DI / IoC / AOP and so on introduce other kinds of dependency that are not apparent in the .class file structure.)

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

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