How to get a list of classes in a project that are no longer needed by anything in this project

Is there a way to generate a list of classes in a Java project that are no longer needed by any other classes in this project?

Here's a diagram illustrating the situation (I hope you enjoy the ASCII diagram, as I don't have enough advertising to use the image), where C and B depend on project A:

A / \ / \ CB 

I started refactoring by moving the code from B to A so that it could share C and B. However, now when I am nearing the end of refactoring, I want to check if there are any classes that I moved to A, which can now be moved back to B (classes that are in A but not used by any code in A)

Is there any tool I can use to create a list of such classes for me?

+7
source share
2 answers

JBoss Tattletale works well for this. I used it in the past to find out which third-party libraries our project no longer needs, and also to learn about the potentially conflicting packages / classes that are present in several JAR files.

+6
source

Run your program with - verbose: the class flag in the JVM. Redirect the output to a file. Implement your program - do your tests or whatever. Upload the name of each loaded class. Run find over your build output directories to list all your classes. Compare the results to find something in your build output directories that are not on the list of loaded classes.

+1
source

All Articles