Class ClasspathUtils


  • public final class ClasspathUtils
    extends Object
    Utilities for working with the Java classpath.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean find​(String aFileName)
      Finds the first instance of the supplied file name in the classpath (in either a directory or jar file) and returns a URL for it.
      static URL findFirst​(String aFileName)
      Finds the first instance of the supplied file name in the classpath (in either a directory or a jar file) and returns a URL for it.
      static File[] getDirFiles()
      Returns an array of all the directories in the system classpath
      static File[] getDirFiles​(FilenameFilter aFilter)
      Returns an array of all the directories in the system classpath that match the supplied FilenameFilter
      static String[] getDirs()
      Returns an String array of all the directory names in the system classpath
      static String[] getDirs​(FilenameFilter aFilter)
      Returns an String array of all the directory names in the system classpath that match the supplied FilenameFilter
      static JarFile[] getJarFiles()
      Returns an array of all the jar files in the system classpath
      static JarFile[] getJarFiles​(FilenameFilter aFilter)
      Returns an array of all the jar files in the system classpath that match the supplied FilenameFilter
      static String[] getJars()
      Returns an String array of all the names of the jars in the system classpath
      static String[] getJars​(FilenameFilter aFilter)
      Returns an String array of all the names of the jars in the system classpath that match the supplied FilenameFilter
    • Method Detail

      • getDirs

        public static String[] getDirs()
        Returns an String array of all the directory names in the system classpath
        Returns:
        The names of directories from the system classpath
      • getDirFiles

        public static File[] getDirFiles()
        Returns an array of all the directories in the system classpath
        Returns:
        The directories from the system classpath
      • getDirs

        public static String[] getDirs​(FilenameFilter aFilter)
        Returns an String array of all the directory names in the system classpath that match the supplied FilenameFilter
        Parameters:
        aFilter - A filter to use while retrieving directories
        Returns:
        The names of directories from the system classpath that match the supplied FilenameFilter
      • getDirFiles

        public static File[] getDirFiles​(FilenameFilter aFilter)
        Returns an array of all the directories in the system classpath that match the supplied FilenameFilter
        Parameters:
        aFilter - A filter to use while retrieving directories
        Returns:
        The directories from the system classpath that match the supplied FilenameFilter
      • getJars

        public static String[] getJars()
        Returns an String array of all the names of the jars in the system classpath
        Returns:
        The names of jars from the system classpath
      • getJars

        public static String[] getJars​(FilenameFilter aFilter)
        Returns an String array of all the names of the jars in the system classpath that match the supplied FilenameFilter
        Parameters:
        aFilter - A file name filter to use while retrieving Jar files
        Returns:
        The names of jars from the system classpath that match the supplied FilenameFilter
      • getJarFiles

        public static JarFile[] getJarFiles()
                                     throws IOException
        Returns an array of all the jar files in the system classpath
        Returns:
        The jar files from the system classpath
        Throws:
        IOException - If there is trouble reading the file system while looking for Jar files
      • getJarFiles

        public static JarFile[] getJarFiles​(FilenameFilter aFilter)
                                     throws IOException
        Returns an array of all the jar files in the system classpath that match the supplied FilenameFilter
        Parameters:
        aFilter - A file name filter to use while retrieving Jar files
        Returns:
        The jar files from the system classpath that match the supplied FilenameFilter
        Throws:
        IOException - If there is trouble reading the file system while looking for Jar files
      • findFirst

        public static URL findFirst​(String aFileName)
                             throws IOException
        Finds the first instance of the supplied file name in the classpath (in either a directory or a jar file) and returns a URL for it.
        Parameters:
        aFileName - The name of the file we want to read
        Returns:
        The URL of the file we want to read
        Throws:
        IOException - If there is trouble reading from the file system or jars
      • find

        public static boolean find​(String aFileName)
                            throws IOException
        Finds the first instance of the supplied file name in the classpath (in either a directory or jar file) and returns a URL for it.
        Parameters:
        aFileName - The name of the file we want to read
        Returns:
        True if the file is found in the classpath; else, false
        Throws:
        IOException - If a directory or jar file can't be read