Brandon Yarbrough
Brandon Yarbrough

Reputation: 38399

Find unused code in Java webapp

I have a Tomcat-powered webapp that builds to a war and is deployed. It's been used for a few somewhat different tasks over the years, and it has lots and lots and lots of classes and libraries.

I'd like to do some sort of automated census of used and unused classes (and maybe even dependencies) and get a report back for which classes, methods, or even lines that have not been executed over a few days of production use.

Is there a tool that could generate such a report for me?

Upvotes: 0

Views: 326

Answers (2)

Baski
Baski

Reputation: 839

If you are talking about statistics of unused code (functionally) in production system you can start with simply enabling the "-verbose:class" as startup parameter. I don't think Sun JDK (at least JDK 5)supports regular expression to restrict the log to specific package(s).

It's better to analyze the unused method/block using static analysis tools like PMD/Sonar rather than instrumenting to method/line level.

Upvotes: 0

desau
desau

Reputation: 3021

You're looking for a code coverage tool.

For Java, try EMMA:

http://emma.sourceforge.net/

Upvotes: 2

Related Questions