Trimming my Java Project
Asked Answered
H

2

7

I am currently working on a project that utilizes the jfreechart library. I am currently using the jar file for this library by adding it in my build path. However I do not need the entire functionality of the library. I would like to carve out only those sections of the library I have used my code and obviously the dependent code.

My ultimate aim is to reduce the size of the project. I have to meet some size targets and using the entire 7 mb jar library is not an option.

I wanted to know if there is a way to do this apart from manually checking for dependencies?

I would ideally like to apply any suggested method to the jar file of the library but if there is a convenient way to detect unused code in the source code I am willing to import the source code into my project.

I apologize if my request is a repeat or a stupid question.

Thanks, Sudipto

Homology answered 17/7, 2011 at 9:24 Comment(3)
Generally manually playing with a library may not be a very good idea. You will not be able to apply updates, for instance. (You probably already know this and have a very specific requirement) (also, if you say why 7mb is the limit, there can be other alternatives as well to solve it)Pyrites
Thanks for your input nivas, but the reason i would prefer not to go beyond 1 or 2 mb in file size is that the project is a plugin for 'cytoscape' and most other plugins are quite small. I realize that this is a somewhat arbitrary reason but its not really my decision, my project supervisor did not agree that ease of update was reason enough to have a large file size.Homology
Try proguard or jarjar #476016Ushijima
M
5

Unfortunately, you can't do this without (arguably) violating the JFreeChart license.

JFreeChart is licensed under the Lesser GNU Public License, and one of the tenets of that license is that the end-user should be free to modify or replace the licensed software embedded in your software. If you cherry-pick classes from JFreeChart and incorporate them into your JAR, you make it difficult for your users to exercise their right to replace the embedded JFreeChart classes. This is certainly against the spirit of the LGPL.

For more details, refer to the GNU LGPL and Java page.


If you want to do this kind of thing with JFreeChart, you will need to get permission from the copyright holder. If your supervisor is really keen to keep the download size down, a large cash donation to the JFreeChart project might help them come around to his way of thinking. (Disclaimer - I have no connection whatsoever to the project.)

Muller answered 17/7, 2011 at 9:50 Comment(0)
P
4

This can indeed be hard to determine because execution paths of an application can differ per run. However there is the Instrumentation interface which can show you all the classes currently loaded by the JVM. That should give you an idea which classes to keep. As long as you have run all the possible outcomes of the application.

Generally speaking, this is of course a bad idea, but since you've asked...

Petition answered 17/7, 2011 at 9:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.