• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Tool to display unused classes in a project

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

We have a huge java project with a whole bunch of packages and since a lot of different people worked on it over the last 1,5 years it's full of unnecessary methods,classes and even packages.
Could anybody let me know if there was a tool that displays unnecessary components in a java project?
Thank you.
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know any specifically designed for this, but some options are
1) Run the JVM with the verbose flag. It will print out each class it loads. Your run would have to put the program through its paces, in order to make sure you exercise each needed class. Even if it's not perfect, it's a good starting point, and can be done at very low cost.
2) IIRC JBuilder has a jar wizard which can supposedly figure out which classes are needed. Other IDEs maye have as well.
3) Most obfuscation tools will look for unused classes and methods. They tend to be prety good (unless reflection or advanced classloading techniques are used). I don't know if they can explicitly tell you what's not needed, you may have to simply obfuscate the code (or maybe run it sans obfuscation) and compare the output jars to the source.

--Mark
hershey@vaultus.com
 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
how about doing a "clean build"
delete all classes, compile just the main class and this should lead to compilation of all used classes since compiler needs to resolve the files. shouldnt it ?
this does not work if you have dynamic class loading with Class.forName and so on.

karl
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JProbe Coverage will show you code coverage based on actual use (or rather testing), but given things like reflection and dynamic classloading, it is probably not possible to statically analyze a code base to determine this.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is one more: http://www.optimizeit.com
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic