Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove unused jars from project

Tags:

java

jar

ant


What is the easiest way (tool ?) to remove unused jars from my java (ant ) project. Our project has become really huge, and we want to do a clean up. There are several jars that are added to the classpath, but not all are used for compile/run. Is there a way to identify the unnecessary jars by running some utility from command line?
Note: we do not want to follow the tedious process of removing one or more jars, then compile/run to test if those are required or not.

like image 270
flowerpot Avatar asked Sep 30 '13 16:09

flowerpot


People also ask

How do I remove a jar from a project?

Select Project in Project Explorer and Press "Alt+Enter" then Go to Java Build path and select Libraries then select jar file finally click on Remove button. select jar in the Project tree-view and right click on it and select Build Path then in select the Remove from Build Path . You are done.

Can jar files have viruses?

The most prominent JAR malware, that has been around since January 2013 is 'Adwind'. This RAT (Remote Access Trojan) takes advantage of JAR's cross-platform features, and can be executed on Windows, Mac OSX, Linux and since August 2013- Android OS.


1 Answers

If there's a better solution to this, I'd love to hear it.

The problem is that even if a jar isn't needed to compile, it could be needed to run. And this "need" could be transitive. EG: A jar you use needs a jar you don't use and only at runtime. As is the nature of runtime errors, they'll only reveal themselves when you try to execute the code. Worst case, that may not occur until you're running in production.

The best solution I know of is exactly what you don't want to do: "removing one or more jars, then compile/run to test if those are required or not".

like image 99
Daniel Kaplan Avatar answered Nov 08 '22 19:11

Daniel Kaplan