public class

ClasspathUtils

extends Object
java.lang.Object
   ↳ com.atlassian.confluence.util.ClasspathUtils

Class Overview

Classpath discovery utilities

Summary

Public Constructors
ClasspathUtils()
Public Methods
static List<URL> getClassLoaderClasspath(ClassLoader classloader)
Get the classpath searched for by a particular classloader (only supports URLClassLoaders presently)
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 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 URL[] getSystemClasspath()
This method will return an array of URLs used by the system classloader.
static List<ClassLoader> getThreadContentClassLoaderHierarchy()
Get a list of classloaders in the thread context classloader hierarchy
static URL[] getThreadContextClasspath()
This method will return an array of URLs used by the thread context classloader.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ClasspathUtils ()

Public Methods

public static List<URL> getClassLoaderClasspath (ClassLoader classloader)

Get the classpath searched for by a particular classloader (only supports URLClassLoaders presently)

Parameters
classloader to examine
Returns
  • List of paths searched on by the classloader, or null if the classloader does not support path discovery

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 by getClassLoaderClasspath(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.

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.

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.

public static URL[] getSystemClasspath ()

This method will return an array of URLs used by the system classloader. If the system classloader is not an instance of URLClassLoader, this method will return null

Returns
  • Array of URLs in classpath lookup order or null if system classloader does not support classpath discovery

public static List<ClassLoader> getThreadContentClassLoaderHierarchy ()

Get a list of classloaders in the thread context classloader hierarchy

Returns
  • list of classloaders in order of delegation

public static URL[] getThreadContextClasspath ()

This method will return an array of URLs used by the thread context classloader. This method will search the classloader hierarchy for all classloaders of class URLClassLoader and return all URLs searched by these classloaders in order of discovery. If no such classloaders are found this method will return null

Returns
  • Array of URLs in classpath as reported by all URLClassLoaders in the classloader hierarchy, null if no such classloaders exist.