Finding unused jars used in an eclipse project


Java Problem Overview

Are there any plugins/tools available to go through the classpath of an eclipse project (or workspace) and highlight any unused jars?

Java Solutions

Solution 1 - Java

ClassPathHelper is a good start.

It automatically identifies orphan jars and much more.

The only limitation is with dependencies that are not defined in classes, e.g. in dependency injection framework configuration files.

You also have other options/complements, such as:

  • workingfrog "Relief", which relies on the ability to deal with real objects by examining their shape, size or relative place in space it gives a "physical" view on java packages, types and fields and their relationships, making them easier to handle.

  • Unnecessary Code Detector: a eclipse PlugIn tool to find unnecessary (dead) public java code.

Solution 2 - Java

UCDetector does not help for this : It does not work on JARs. And for classpathHelper, I wan't able to find out an easy way just to list the orphan JARs (BTW, if someone has a tutorial for this, i am interested).

So, if you are also using Maven as I do, I find out this great Maven plugin, and I would like to share this solution with you. Just type :

mvn dependency:analyze

And you will instantly get a list of unused JARs in your dependencies. Very handy !

Solution 3 - Java

I found a very fast and interesting tool to archive this goal:

Just unzip the program and run:

java -Xmx512m -jar tattletale.jar ~/myjavaproject/mydistribution output

This will generate a very impressive report with different points (text from their site):

  • Identify dependencies between JAR files
  • Find missing classes from the classpath
  • Spot if a class/package is located in multiple JAR files
  • Spot if the same JAR file is located in multiple locations
  • With a list of what each JAR file requires and provides
  • Verify the SerialVersionUID of a class
  • Find similar JAR files that have different version numbers
  • Find JAR files without a version number
  • Find unused JAR archives
  • Identify sealed / signed JAR archives
  • Locate a class in a JAR file
  • Get the OSGi status of your project
  • Remove black listed API usage
  • And generate the same reports for your .WAR and .EAR archives

Solution 4 - Java

You can use one of this plugins: UCDetector or Classpath Helper

Solution 5 - Java

I know this is an old one, but if anyone else stumbles upon this, Eclipse does this by itself.

Navigate to Project properties->Java Code Style->Clean Up Select the Eclipse [Built-in] and it does the following:

  • Change non static accesses to static members using declaring type
  • Change indirect accesses to static members to direct accesses (accesses through subtypes)
  • Remove unused imports
  • Add missing '@Override' annotations
  • Add missing '@Override' annotations to implementations of interface methods
  • Add missing '@Deprecated' annotations
  • Remove unnecessary casts
  • Remove unnecessary '$NON-NLS$' tags

Solution 6 - Java

In the Maven and Gradle projects you can use those plugins to identify unused dependencies.

Use this in the pom.xml file plugin.


this will give as output. In this case we add commons-collections dependency to pom.xml, but do not use in the code. enter image description here

Use this in the build.gradle file plugin.

plugins {
  id "ca.cutterslade.analyze" version "1.7.1"

Using legacy plugin application:

enter image description here

this will give as output. In this case we add dependencies unusedDeclaredArtifacts to gradlefile, but do not use in the code. enter image description here


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRodeoClownView Question on Stackoverflow
Solution 1 - JavaVonCView Answer on Stackoverflow
Solution 2 - JavaRaphael JolivetView Answer on Stackoverflow
Solution 3 - JavabobbelView Answer on Stackoverflow
Solution 4 - JavaKS2008View Answer on Stackoverflow
Solution 5 - JavaJon CarlstedtView Answer on Stackoverflow
Solution 6 - JavaChamithView Answer on Stackoverflow