Package com.atlassian.confluence.util
Class ClasspathUtils
- java.lang.Object
-
- com.atlassian.confluence.util.ClasspathUtils
-
public class ClasspathUtils extends Object
Classpath discovery utilities
-
-
Constructor Summary
Constructors Constructor Description ClasspathUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static List<String>
getClassesFromJar(URL jarUrl)
Get a list of class files in the JAR specified by a URL.static ClasspathClasses
getClassesInClasspathJars()
Gets a list of JARs from the thread context classloader, and returns a ClasspathClasses object with the class file names and the JARs which they appear in.static List<URL>
getClassLoaderClasspath(ClassLoader classloader)
Get the classpath searched for by a particular classloader (only supportsURLClassLoader
s presently)static ClasspathClasses
getFilesInClasspathJars()
Gets a list of JARs from the thread context classloader, and returns a ClasspathClasses object with the class file names and the JARs which they appear in.static Optional<File>
getJarFileFromClass(Class clazz)
If the provided class has been loaded from a jar file, will find the absolute path to that jar file.static URL[]
getSystemClasspath()
Deprecated.since 7.0.1static List<ClassLoader>
getThreadContentClassLoaderHierarchy()
Get a list of classloaders in the thread context classloader hierarchystatic URL[]
getThreadContextClasspath()
This method will return an array of URLs used by the thread context classloader and its parent classloaders.
-
-
-
Method Detail
-
getSystemClasspath
@Deprecated public static URL[] getSystemClasspath()
Deprecated.since 7.0.1This method will return an array of URLs used by the system classloader.- Returns:
- Array of URLs in classpath lookup order
-
getThreadContextClasspath
public static URL[] getThreadContextClasspath()
This method will return an array of URLs used by the thread context classloader and its parent classloaders.- Returns:
- Array of URLs loaded in the classpath.
-
getThreadContentClassLoaderHierarchy
public static List<ClassLoader> getThreadContentClassLoaderHierarchy()
Get a list of classloaders in the thread context classloader hierarchy- Returns:
- list of classloaders in order of delegation
-
getClassLoaderClasspath
public static List<URL> getClassLoaderClasspath(ClassLoader classloader)
Get the classpath searched for by a particular classloader (only supportsURLClassLoader
s presently)- Parameters:
classloader
- to examine- Returns:
- List of paths searched on by the classloader, or null if the classloader does not support path discovery
-
getClassesFromJar
public static List<String> getClassesFromJar(URL jarUrl)
Get a list of class files in the JAR specified by a URL.- Parameters:
jarUrl
- the URL of a JAR on the classpath, such as one of the items in the list returned bygetClassLoaderClasspath(ClassLoader)
- Returns:
- a List of Strings which are the class files in the JAR, an empty list if the JAR contains no class files or null if the JAR cannot be opened.
-
getClassesInClasspathJars
public static ClasspathClasses getClassesInClasspathJars()
Gets a list of JARs from the thread context classloader, and returns a ClasspathClasses object with the class file names and the JARs which they appear in. Useful for finding duplicate classes in the classpath.- Returns:
- a ClasspathClasses object contains classes found in JARs on the classpath. If the thread context classloader is not a URLClassLoader, returns null.
- See Also:
getThreadContextClasspath()
-
getFilesInClasspathJars
public static ClasspathClasses getFilesInClasspathJars()
Gets a list of JARs from the thread context classloader, and returns a ClasspathClasses object with the class file names and the JARs which they appear in. Useful for finding duplicate classes in the classpath.- Returns:
- a ClasspathClasses object contains classes found in JARs on the classpath. If the thread context classloader is not a URLClassLoader, returns null.
- See Also:
getThreadContextClasspath()
-
-