Class ClasspathCollector

java.lang.Object
com.pnfsoftware.jeb.util.reflect.ClasspathCollector

public class ClasspathCollector extends Object
Collect classpaths and build a ClassLoader object using those paths.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an empty classpath collector.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(String paths)
    Add a path or series of paths to the collection of classpath entries recorded by this object.
    boolean
    Add a JAR file (as well as additional in-manifest located entries) to the collection of classpath entries recorded by this object.
    void
    addSmart(File dir, String cplist)
    Add a series of comma-separated entries to the collection of classpath entries recorded by this object.
    Create a classloader whose parent is the current classloader and whose classpath consists of all classpaths collected by this object
    Retrieve or create a classloader holding the classpaths stored by this object.
    Get the collected classpath URLs.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ClasspathCollector

      public ClasspathCollector()
      Create an empty classpath collector.
  • Method Details

    • getUrls

      public List<URL> getUrls()
      Get the collected classpath URLs.
      Returns:
      an immutable view of the collected URLs
    • addSmart

      public void addSmart(File dir, String cplist)
      Add a series of comma-separated entries to the collection of classpath entries recorded by this object. The entries may point to folders or JAR files.
      Parameters:
      dir - base directory used to resolve relative entries
      cplist - comma-separated list of classpath entries or wildcard patterns
    • add

      public boolean add(String paths)
      Add a path or series of paths to the collection of classpath entries recorded by this object.
      Parameters:
      paths - single or multiple paths. In the case of multiple paths, the paths must be separated by the system separator, that is ':' on Unix systems, and ';' on Windows systems
      Returns:
      false if some error happened
    • addFromJar

      public boolean addFromJar(File file)
      Add a JAR file (as well as additional in-manifest located entries) to the collection of classpath entries recorded by this object.
      Parameters:
      file - JAR file to add
      Returns:
      false if some error happened
    • createClassloader

      public URLClassLoader createClassloader()
      Create a classloader whose parent is the current classloader and whose classpath consists of all classpaths collected by this object
      Returns:
      a URL class loader for the collected classpath
    • getClassloader

      public URLClassLoader getClassloader(ClassLoader parentCl)
      Retrieve or create a classloader holding the classpaths stored by this object.
      Parameters:
      parentCl - optional parent class loader; if null, the collector's class loader is used
      Returns:
      a URL class loader for the collected classpath
    • toString

      public String toString()
      Overrides:
      toString in class Object