开发者

Find unused code in Java webapp

开发者 https://www.devze.com 2023-01-07 02:03 出处:网络
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 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 autom开发者_JAVA技巧ated 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?


You're looking for a code coverage tool.

For Java, try EMMA:

http://emma.sourceforge.net/


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消