选择性罐子包装 [英] Selective jar packaging

查看:131
本文介绍了选择性罐子包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的program.jar,它使用了巨大的library.jar的一小部分。

I have my small program.jar that uses a small part of huge library.jar.

是否有工具将几个罐子重新包装成一个,所以它可以是单独运行并且尽可能小?

Is there a tool to repackage several jars into one so it can be run stand-alone and is as small as possible?

更新大小很重要。

推荐答案

使用ant和maven插件有 proguard 。它删除了未使用的代码,可选择混淆和压缩到一个jar。

There is proguard, with ant and maven plugins. It removes unused code, optionally obfuscates and compresses to a single jar.

Proguard减少了两个方面的大小

Proguard reduces the size on two fronts


  1. 只有实际使用的类存储在最终的jar中。

  2. 长名称,例如所有长包名,类名,都被重命名为更短的名称,节省了相当多的空间。

确定是否有类在java中使用有点棘手。静态代码分析可以让你到目前为止,但你需要通过反射访问一些小心的代码,因为该工具可能无法检测到。它处理Class.forName(xyzFoo)但是更复杂,你需要将它添加到要包含的类的配置文件中,可以让类加载器生成在运行时使用的类列表,这样这不一定非常艰巨。

Determining whether a class is used in java is a bit tricky. Static code analysis can get you so far, but you need to be a bit careful code accessed via reflection, since the tool may not be able to detect that. It handles Class.forName("x.y.z.Foo") but anything more complex and you'll need to add it to a config file of classes to include, It's possible to have a classloader generate a list of classes that are used at runtime, so this doesn't have to be arduous.

您可能还想调查 pack200 压缩方案,因为这也可以大大减少jar的大小。

You might also want to investigate the pack200 compression scheme, as this can also bring a significant reduction in size of the jar.

这篇关于选择性罐子包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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