Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Minimize Dependencies

I have a situation where there is a small piece of Java code that has a large number of jars that it depends on. However, the dependencies inside these jars are very shallow. In most cases it only depends on a jar for a single interface.

Instead of distributing all of the jars with the application, I would like to just distribute the specific class files inside the jars that it actually uses. The reason for this is to conserve space (this code will live in an applet).

Does anyone know of a tool or method to do this automatically? Assuming all of the dependencies are static, this seems entirely possible. Any ideas?

like image 795
ghempton Avatar asked Sep 08 '09 07:09

ghempton


3 Answers

Classdepandjar will strip down a codebase to the essential classes. It's used in the Jini world for delivering optimally-sized jars, but there's nothing Jini-specific about it.

Available as an Ant task.

like image 107
Brian Agnew Avatar answered Oct 24 '22 04:10

Brian Agnew


As far as I know, this is maven only, but it's a good start

Maven Shade Plugin: This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.

like image 31
Robert Munteanu Avatar answered Oct 24 '22 03:10

Robert Munteanu


ProGuard does shrinking/optimizingh and also obfuscation. I think you can config it to do just one or the other.

like image 22
pjz Avatar answered Oct 24 '22 03:10

pjz