Class Classpath


  • public final class Classpath
    extends java.lang.Object
    A class path accumulator.

    You can build a class path by repeatedly calling the addXxx methods, then use the getXxx methods to get the accumulated class path.

    • Constructor Summary

      Constructors 
      Constructor Description
      Classpath()
      Default constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addComponent​(java.io.File component)
      Adds a class path component.
      boolean addComponent​(java.lang.String component)
      Adds a class path component.
      void addFilesFromPath​(java.io.File path)
      Scans a directory and adds all files ending with ".jar" or ".zip" to the class path.
      java.net.URL[] getUrls()
      Returns a list of class path component URLs.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • Classpath

        public Classpath()
        Default constructor.
    • Method Detail

      • addComponent

        public boolean addComponent​(java.io.File component)
                             throws java.io.IOException
        Adds a class path component. The component may be a directory or a file. If component does not exist, the method does nothing.
        Parameters:
        component - The class path component to add
        Returns:
        true if the component was added
        Throws:
        java.io.IOException - if there was a problem parsing the component
        java.lang.IllegalArgumentException - if component is null
      • addComponent

        public boolean addComponent​(java.lang.String component)
                             throws java.io.IOException
        Adds a class path component. The component may be a directory or a file. If component does not exist, the method does nothing.
        Parameters:
        component - The class path component to add
        Returns:
        true if the component was added
        Throws:
        java.io.IOException - if there was a problem parsing the component
        java.lang.IllegalArgumentException - if component is null or empty
      • addFilesFromPath

        public void addFilesFromPath​(java.io.File path)
                              throws java.io.IOException
        Scans a directory and adds all files ending with ".jar" or ".zip" to the class path. If path is not a directory, the method does nothing.
        Parameters:
        path - the directory to scan
        Throws:
        java.io.IOException - if there was a problem processing the directory
        java.lang.IllegalArgumentException - if path is null
      • getUrls

        public java.net.URL[] getUrls()
                               throws java.net.MalformedURLException
        Returns a list of class path component URLs.
        Returns:
        A list of class path component URLs
        Throws:
        java.net.MalformedURLException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object