Class JarUtils


  • public class JarUtils
    extends java.lang.Object
    Jarfile utilities.
    • Constructor Summary

      Constructors 
      Constructor Description
      JarUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String classfilePathToClassName​(java.lang.String classfilePath)
      Convert a classfile path to the corresponding class name.
      static java.lang.String classNameToClassfilePath​(java.lang.String className)
      Convert a class name to the corresponding classfile path.
      static java.lang.ClassLoader createURLClassLoaderFromPathString​(java.lang.String classpathStr)
      Create a custom URLClassLoader from a classpath path string.
      static java.lang.String leafName​(java.lang.String path)
      Returns the leafname of a path, after first stripping off everything after the first '!', if present.
      static void logJavaInfo​(LogNode log)
      Log the Java version and the JRE paths that were found.
      static java.lang.String pathElementsToPathStr​(java.lang.Iterable<?> pathElts)
      Get a set of path elements as a string, from an array of objects (e.g.
      static java.lang.String pathElementsToPathStr​(java.lang.Object... pathElts)
      Get a set of path elements as a string, from an array of objects (e.g.
      static java.lang.String[] smartPathSplit​(java.lang.String pathStr)
      Split a path on File.pathSeparator (':' on Linux, ';' on Windows), but also allow for the use of URLs with protocol specifiers, e.g.
      • Methods inherited from class java.lang.Object

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

      • JarUtils

        public JarUtils()
    • Method Detail

      • smartPathSplit

        public static java.lang.String[] smartPathSplit​(java.lang.String pathStr)
        Split a path on File.pathSeparator (':' on Linux, ';' on Windows), but also allow for the use of URLs with protocol specifiers, e.g. "http://domain/jar1.jar:http://domain/jar2.jar". This is really not even handled by the JRE, in all likelihood, but it's better to be robust.
        Parameters:
        pathStr - The path to split.
        Returns:
        The path element substrings.
      • createURLClassLoaderFromPathString

        public static java.lang.ClassLoader createURLClassLoaderFromPathString​(java.lang.String classpathStr)
        Create a custom URLClassLoader from a classpath path string.
        Parameters:
        classpathStr - The classpath string.
        Returns:
        A custom URLClassLoader that can load from the path string.
      • pathElementsToPathStr

        public static java.lang.String pathElementsToPathStr​(java.lang.Object... pathElts)
        Get a set of path elements as a string, from an array of objects (e.g. of String, File or URL type, whose toString() method will be called to get the path component), and return the path as a single string delineated with the standard path separator character.
        Parameters:
        pathElts - The path elements.
        Returns:
        The delimited path formed out of the path elements.
      • pathElementsToPathStr

        public static java.lang.String pathElementsToPathStr​(java.lang.Iterable<?> pathElts)
        Get a set of path elements as a string, from an array of objects (e.g. of String, File or URL type, whose toString() method will be called to get the path component), and return the path as a single string delineated with the standard path separator character.
        Parameters:
        pathElts - The path elements.
        Returns:
        The delimited path formed out of the path elements, after calling each of their toString() methods.
      • leafName

        public static java.lang.String leafName​(java.lang.String path)
        Returns the leafname of a path, after first stripping off everything after the first '!', if present.
        Parameters:
        path - A file path.
        Returns:
        The leafname of the path.
      • classfilePathToClassName

        public static java.lang.String classfilePathToClassName​(java.lang.String classfilePath)
        Convert a classfile path to the corresponding class name.
      • classNameToClassfilePath

        public static java.lang.String classNameToClassfilePath​(java.lang.String className)
        Convert a class name to the corresponding classfile path.
      • logJavaInfo

        public static void logJavaInfo​(LogNode log)
        Log the Java version and the JRE paths that were found.
        Parameters:
        log - The log.