Package org.rapidcontext.util
Class ClasspathUtil
java.lang.Object
org.rapidcontext.util.ClasspathUtil
A set of utility methods for working with the classpath and class loaders.
- Version:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClassLoader
classLoader
(Class<?> cls) Returns the class loader for the specified class.static URL
Returns the resource URL corresponding the the specified class.static URL
Returns the resource URL corresponding the the specified path.static File
locateFile
(Class<?> cls) Returns the file containing the specified class.static Manifest
Returns the manifest for the JAR file containing the specified class.static String
manifestAttribute
(Class<?> cls, String name) Returns a single attribute value from the JAR manifest for a class.
-
Method Details
-
classLoader
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
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
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 usepath
- the resource path- Returns:
- the resource URL, or null if not found
-
locateFile
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
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
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 checkname
- the main attribute name- Returns:
- the attribute value, or null if not found
-