Class ClassPath

java.lang.Object
com.google.common.reflect.ClassPath

public final class ClassPath extends Object
Scans the source of a ClassLoader and finds all loadable classes and resources.

Prefer alternatives to classpath scanning

Runtime classpath scanning is expensive because it traverses the entire transitive classpath, which can cause performance issues such as startup latency regressions. (It also does not support Android.) Before scanning the classpath at runtime, consider whether your use case can be solved with compile-time or static mechanisms:

  • Compile-time service registration / annotation processors (e.g., @AutoService)
  • Dependency injection (e.g., Dagger, Guice)
  • Explicit static registries or configuration
  • Compile-time classpath scanning, such as that of ClassGraph, but compile-time scanning is likewise costly, so prefer the other options when possible

Limitations of ClassPath (for those who do need classpath scanning)

In the case of directory classloaders, symlinks are supported but cycles are not traversed. This guarantees discovery of each unique loadable resource. However, not all possible aliases for resources on cyclic paths will be listed.

Since:
14.0
Author:
Ben Yu