最小化 jar 依赖大小

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

问题描述

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

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.

减小罐子尺寸的最佳方法是什么.我应该下载源代码并用我需要的类构建一个 jar 吗?哪些现有工具可以帮助实现这一点(例如,我简要地查看了 http://code.google.com/p/jarjar/)?

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

谢谢

编辑 1:我想减小我的第三方官方"罐子的大小,如 swingx-1.6.jar (1.4 MB)、set-3.6 (1.7 MB) glazedlists-1.8.jar (820kB) 等,以便它们只包含我需要的最低限度的课程

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

编辑 2:如果库使用反射,则手动或使用 proguard 之类的程序最小化 jar 会更加复杂.使用 google guice 注入不再起作用用proguard混淆后

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

cletus 在另一篇文章中的回答非常好 如何判断Java程序使用了哪些类?

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

推荐答案

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

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.

我发现 Proguard 非常有效 - 一开始可能有点难以理解.但是我没有任何类似的经验来提供比较.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)