我有一个小的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
确定是否有类在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.
更多推荐
选择性罐子包装
发布评论