| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Classpath and module path finding is implemented by the classgraph-classpath library, which can also be used on its own, without scanning anything -- see the Classpath API. The following mechanisms are handled:
The module path (Project Jigsaw), using this mechanism to find all visible modules.
Multi-release jars on the traditional classpath, emulating the JPMS semantics for overriding the "base section" using "versioned sections" contained in paths of the form META-INF/versions/X, where X is an integer greater than or equal to 9, and less than or equal to the running JVM version. (N.B. This requires the manifest file to contain the attribute Multi-Release: true.)
The standard (now legacy) Java URLClassLoader and subclasses.
The java.class.path system property, supporting specification of the classpath using the -cp JRE commandline switch.
ClassGraph includes reflection code to extract path entries from specific classloaders from a wide range of common runtime environments:
Remotely-hosted jarfiles, specified using http:// or https:// URLs. (Some ClassLoaders allow this.) This is disabled by default for security reasons, along with ftp: and mailto: -- a classpath is not always something you wrote. If .enableRemoteJarScanning() is called before .scan(), any remote jars are downloaded to a ByteBuffer in RAM, or if the jar is too large, the jar is spilled over to a temporary file on disk. (Note that if your classpath contains remote jars, they will be downloaded every time the classpath is scanned. Both ClassGraph and the context ClassLoader may separately download the same jarfiles.)
Jarfiles specified using custom URL schemes. A scheme the application has registered a URLStreamHandler or a java.nio.file.spi.FileSystemProvider for is scanned without being enabled -- registering the handler is already the statement that those URLs are meant to be read, and there is no way to enumerate the registered schemes to check. If a custom URI scheme is not backed by an underlying FileSystem implementation, then URL.openConnection() is used to open the URL, and if the data fetched over the connection is large, it will automatically spill to a temporary file on disk. Naming the scheme with .enableURLScheme("jimfs") is still worthwhile if you pass a ':'-separated classpath string to .enableClasspathEntries(String), since that is what keeps the string from being split at the scheme's own colon.
Classpath elements hosted on custom filesystems such as Jimfs. Supports scanning a classpath URL of custom scheme (e.g. jimfs://) via the NIO Files and Path APIs. This works for URLs that point to either a jarfile or to a directory (ClassGraph figures out which of these the URL points to). If you specify the URL path to a jarfile on a custom filesystem, it will be opened using FileChannel for speed, rather than calling URL.openConnection().
Wildcarded classpath entries, e.g. lib/* (which includes all jars and directories in lib/ as separate classpath entries), which is allowed as of JDK 6. (Only whole-directory globs are currently supported, so lib/proj* doesn't work, but this should match the JRE's behavior.)
Class-Path entries in a jarfile's manifest file, whereby jarfiles may add other external jarfiles to their own classpaths, with paths resolved relative to the parent directory or parent jarfile of the manifest's jarfile. ClassGraph is able to determine the transitive closure of these references, breaking cycles if necessary.
Bundle-ClassPath entries in an OSGi bundle jarfile's manifest file, which allows a bundle to add nested jars to the bundle classpath, with paths resolved relative to the root of the bundle jarfile.
Jarfiles within jarfiles (to unlimited nesting depth), e.g.
project.jar!/BOOT-INF/lib/dependency.jar, as required by Spring-Boot, JBoss, and Felix classloaders, and probably others.
Zip64-format jarfiles
The package hierarchy being rooted at a non-root path within a jarfile, e.g. BOOT-INF/classes/ (Spring Boot), WEB-INF/classes/ (Tomcat), and classes/ (Ant). Name the package root as part of the classpath entry, e.g. app.jar!/BOOT-INF/classes, and the entries below it are reported relative to it. (Note that the standard Java classloaders do not support this.)
Nested package roots and nested lib jars that a classloader looks for on its own. A classloader loads classes from the classpath elements it was given, and URLClassLoader -- the classloader every other one is measured against -- has no automatic package roots or lib dirs at all, so ClassGraph assumes none either. A directory called classes inside a classpath element is a package named classes, not a package root, unless the classloader that yielded that element has its own code that goes looking there. Two of the supported classloaders do:
Jarfiles in a subdirectory of a lib dir are found too, since a classloader that adds the jarfiles of a lib dir looks below it as well. A Spring Boot application needs no automatic package root: its launcher hands its classloader an explicit URL for BOOT-INF/classes and one for each jarfile in BOOT-INF/lib, so both are ordinary classpath elements. An OSGi bundle likewise names the jarfiles it loads from in its Bundle-ClassPath manifest attribute, which ClassGraph reads. A ClassLoaderHandler you write yourself can declare package roots and lib dirs of its own -- see ClassGraph#registerClassLoaderHandler().
Handles both PARENT_FIRST and PARENT_LAST classloader delegation modes (used by Websphere and Spring Boot), in order to resolve classpath elements in the correct order, mirroring the delegation order of the classloaders that the classpath elements were obtained from. (Standard Java classloaders use PARENT_FIRST delegation.)
| Back | FazBrowse Home | New Git URL |