Class ClasspathUtil

java.lang.Object
org.rapidcontext.util.ClasspathUtil

public final class ClasspathUtil extends Object
A set of utility methods for working with the classpath and class loaders.
Version:
1.0
  • Method Details

    • classLoader

      public static ClassLoader classLoader(Class<?> cls)
      Returns the class loader for the specified class.
      Parameters:
      cls - the class to check
      Returns:
      the class loader for the class, or the system class loader if null
    • locate

      public static URL locate(Class<?> cls)
      Returns the resource URL corresponding the the specified class.
      Parameters:
      cls - the class to check
      Returns:
      the resource URL for the class, or null if not found
    • locate

      public static URL locate(Class<?> cls, String path)
      Returns the resource URL corresponding the the specified path. The resource will be located using the class loader for the specified class. Also, the resource path will be normalized, removing any "classpath:" prefix and normalizing the file path.
      Parameters:
      cls - the base class (loader) to use
      path - the resource path
      Returns:
      the resource URL, or null if not found
    • locateFile

      public static File locateFile(Class<?> cls)
      Returns the file containing the specified class. This method uses the class resource URL to attempt to guess the file system location of the class or JAR file.
      Parameters:
      cls - the class to check
      Returns:
      the absolute file system location for the class, or null if not found
    • manifest

      public static Manifest manifest(Class<?> cls)
      Returns the manifest for the JAR file containing the specified class. The JAR file will be located via the class loader for the specified class.
      Parameters:
      cls - the class to check
      Returns:
      the JAR manifest data, or null if not found
    • manifestAttribute

      public static String manifestAttribute(Class<?> cls, String name)
      Returns a single attribute value from the JAR manifest for a class. The JAR file will be located via the class loader for the specified class.
      Parameters:
      cls - the class to check
      name - the main attribute name
      Returns:
      the attribute value, or null if not found