How to determine which package classes are used in my program?

I have imported packages using *.

Example:

import java.awt.*;

Is there any way to find out which classes of this package I actually use in my program? I need to import only the classes that I actually use for my Java project.

thank

+4
source share
4 answers

It’s good practice not to use * for import unless you use each of them. This will cause the executable to be unnecessarily large.

As the @Bill Lizard said, the compiler will tell you which imports you forgot to add.

-2
source

IDE, ​​ Eclipse, , , .

Eclipse Ctrl + Shift + O ( ).

IntelliJ, Ctrl + Alt + O.

+4

*, , , - , Oracle jdeps, JDK. :

jdeps Java. .class, , JAR ...

, classes, , com.example.Foo:

jdeps -verbose:class -cp classes com.example.Foo

. jdeps .

+3

(getPackage() getClassName()) .

{

    System.out.println(Class.class.forName("java.lang.Integer").getPackage());
 }
 catch(ClassNotFoundException ex) {
    System.out.println(ex.toString());
 }
0

All Articles