Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trimming my Java Project

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

like image 481
Sudipto Shome Avatar asked Jul 17 '11 09:07

Sudipto Shome


People also ask

How do you trim something in Java?

The trim() method in Java String is a built-in function that eliminates leading and trailing spaces. The Unicode value of space character is '\u0020'. The trim() method in java checks this Unicode value before and after the string, if it exists then removes the spaces and returns the omitted string.

What does the trim () do in Java?

Java String trim() Method The trim() method removes whitespace from both ends of a string.

How do you truncate a space in Java?

To remove leading and trailing spaces in Java, use the trim() method. This method returns a copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.

How Use trim and split in Java?

Split and Trim Let's see how we can handle splitting the input and trimming the results in one go. Here, trim() method removes leading and trailing spaces in the input string, and the regex itself handles the extra spaces around delimiter.


2 Answers

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.)

like image 170
Stephen C Avatar answered Sep 22 '22 07:09

Stephen C


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...

like image 41
M Platvoet Avatar answered Sep 23 '22 07:09

M Platvoet