开发者

Determine classes used by a Java application

How would you determine the classes (non Sun JDK classes) loaded / unused by a Java application?

Background:

I have an lega开发者_高级运维cy Java webstart application that has gone through a lot of code changes and now has a lot of classes, most of which are not used. I would like to reduce the download size of the application by only deploying classes that will be used only instead of jaring the all the packages.

I will also use the same process to completely delete these unused classes.


Use java -verbose:class to see what classes are loaded, then use grep (or any other tool) to keep only the lines from your packages.

A small limitation: it will only tell you which classes are really used when they are used, so you must cover all use cases of your application.


You can use a good IDE for that.

For instance Intellij IDEA which analyzes the source code for dependencies and allows you to safely delete a class/method/attribute is is not being used by any other.

That way you can get rid off all your dead code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜