Class ClassLoaderHelper

java.lang.Object
org.citrusframework.util.ClassLoaderHelper

public final class ClassLoaderHelper extends Object
Class loader helper class that is aware of dynamically loaded Maven artifacts. Helper is able to adapt class loaders with the additional dependencies in the form of artifact URLs. The helper also provides class instantiation utilities that make sure to also honor the additional artifacts in classpath.
  • Method Details

    • instantiateType

      public static <T> T instantiateType(String type, Object... initargs)
      Instantiate a type by its name. Uses the current thread context class loader to instantiate.
    • instantiateType

      public static <T> T instantiateType(String type, Class<?> caller, Object... initargs)
      Instantiate a type by its name. Use the given caller to resolve the class loader.
    • instantiateType

      public static <T> T instantiateType(String type, ClassLoader cl, Object... initargs)
      Instantiate a type by its name. Uses given class loader to instantiate.
    • adapt

      public static ClassLoader adapt(ClassLoader cl)
      Adapt given class loader to also use additional artifacts if any. Wraps given class loader if additional artifacts are present.
    • getContextClassLoader

      public static ClassLoader getContextClassLoader()
    • getClassLoader

      public static ClassLoader getClassLoader()
    • getClassLoader

      public static ClassLoader getClassLoader(Class<?> type)
    • addArtifact

      public static void addArtifact(String gav, URL url)
      Adds a permanent dynamic class loader entry in the form of a URL. When this helper resolves class loaders the dynamic entry will be part of the class loader.
    • addArtifact

      public static void addArtifact(String gav, URL url, boolean permanent)
      Adds a dynamic class loader entry in the form of a URL. When this helper resolves class loaders the dynamic entry will be part of the class loader.
    • restore

      public static void restore()
      Clears additional artifacts and restores context class loader to its initial state before adapting.
    • reset

      public static void reset()
      Reset temporary artifacts only.
    • updateContextClassloader

      public static boolean updateContextClassloader()
      Set context class loader for current thread with adapted instance.
    • updateContextClassloader

      public static boolean updateContextClassloader(boolean clearCache)
      Set context class loader for current thread with adapted instance.
    • clearCache

      public static void clearCache()
      Clear cache for resource path lookup. Required after the classpath has been adapted with additional artifacts.