Determine what are the classes actually used in a Java applicationTag(s): Environment


In application, start the JRE with the -verbose:class option

java -verbose:class MyApp

Output:

...
[Loaded java.security.AllPermission from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded java.security.UnresolvedPermission from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded java.security.BasicPermissionCollection from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded rgagnon.WindowsUtils from file:/C:/Apps/rega/eclipseworkspace/rega-jna/bin/]
[Loaded java.lang.IllegalStateException from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded java.lang.Void from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded java.util.zip.Inflater from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded java.util.zip.ZStreamRef from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded java.util.zip.InflaterInputStream from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded java.util.zip.ZipFile$ZipFileInflaterInputStream from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded sun.misc.URLClassPath$JarLoader$2 from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded java.util.jar.Manifest from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
[Loaded java.io.ByteArrayInputStream from C:\Apps\rega\Java\jdk1.7.0_75-32\jre\lib\rt.jar]
...
With JDK8+, you have the -Xlog:class+load to do about the same thing.
...
[0.141s][info][class,load] java.security.AllPermission source: jrt:/java.base
[0.141s][info][class,load] java.security.UnresolvedPermission source: jrt:/java.base
[0.141s][info][class,load] java.security.BasicPermissionCollection source: jrt:/java.base
[0.141s][info][class,load] java.security.SecureClassLoader$DebugHolder source: jrt:/java.base
[0.141s][info][class,load] sun.security.util.Debug source: jrt:/java.base
[0.141s][info][class,load] rgagnon.WindowsUtils source: file:/C:/Apps/rega/eclipseworkspace/rega-jna/bin/
[0.142s][info][class,load] java.lang.IllegalStateException source: jrt:/java.base
[0.142s][info][class,load] java.lang.PublicMethods$MethodList source: jrt:/java.base
[0.142s][info][class,load] java.lang.PublicMethods$Key source: jrt:/java.base
[0.142s][info][class,load] java.lang.Void source: jrt:/java.base
[0.142s][info][class,load] jdk.internal.loader.URLClassPath$JarLoader source: jrt:/java.base
[0.142s][info][class,load] java.util.zip.ZipConstants source: jrt:/java.base
[0.142s][info][class,load] java.util.zip.ZipFile source: jrt:/java.base
[0.143s][info][class,load] jdk.internal.misc.JavaUtilZipFileAccess source: jrt:/java.base
[0.143s][info][class,load] java.util.zip.ZipFile$1 source: jrt:/java.base
[0.143s][info][class,load] sun.net.www.protocol.jar.Handler source: jrt:/java.base
[0.143s][info][class,load] jdk.internal.loader.URLClassPath$JarLoader$1 source: jrt:/java.base
[0.143s][info][class,load] jdk.internal.loader.FileURLMapper source: jrt:/java.base
[0.144s][info][class,load] java.util.jar.JarFile source: jrt:/java.base
[0.144s][info][class,load] jdk.internal.misc.JavaUtilJarAccess source: jrt:/java.base
[0.144s][info][class,load] java.util.jar.JavaUtilJarAccessImpl source: jrt:/java.base...

NOTE: This can be useful if you want to trim a JAR to include only classes actually used.