1

I've noticed that a lot of Javascript/jQuery libraries allow developers to customize the .js file, thus including only the bare minimum functionality to save bandwidth/page load times.

Now when I'm distributing my Java library to clients, is there a way to do the same? I don't like forcing clients to have to include a large library in their application if they're only going to be using a few classes.

Ideally everything would be packaged into a nice JAR file.

EDIT: Something similar to this: http://flowplayer.org/tools/download/index.html

1
  • 1
    Jar files are just Zip files.... with some meta data. It is, thus, possible to build/customize any Jar from any Java or Php, any language with a Zip library tool Commented Jul 13, 2011 at 15:31

2 Answers 2

3

Most obfuscators (including the popular ProGuard) can (and by default will) eliminate unused methods and classes from the jar. They do a nice job of checking that apparently unused classes are not used indirectly by the main program.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm the library developer. I cannot know a priori what the users of my library will use or not use. And I don't think it's safe to assume that all my users will know of ProGuard and will use it to deploy their applications.
I looked at the page you linked to in your edit. Based on that, it seems like you could define the subset versions yourself and generate the appropriate .jar files yourself using ProGuard (turning off all obfuscation options, so it would just filter out unused portions). Then you could tell your users that if none of the predefined subsets met their needs, they should use the full library and run a compression/obfuscation tool themselves.
1

This is one of the things ProGuard does. From the website:

ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes.

2 Comments

See my comment on Ted Hopp's answer.
I had assumed you meant other third party libraries that yours depended on, such as if you used only a single class from the Apache Commons IO library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.