Class JarUtils


  • public class JarUtils
    extends java.lang.Object
    Some helpful Jar methods. Could be partially be replaced by JDK 7 FileSystem, but currently this bundle is built for JDK5.
    Author:
    Holger Eichelberger
    • Constructor Summary

      Constructors 
      Constructor Description
      JarUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isJarURI​(java.net.URI uri)
      Returns whether the given uri is a Jar URI as returned, e.g., by a classloader.
      static boolean isJarURL​(java.net.URL url)
      Returns whether the given url is a JAR URL as returned, e.g., by a classloader.
      static void unpackJar​(java.net.URL url, java.io.File target)
      Unpacks a Jar file denoted by url to the given target folder.
      static void unpackJar​(java.net.URL url, java.lang.String resource, java.io.File target)
      Unpacks a Jar file denoted by url to the given target folder.
      • 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

      • isJarURI

        public static boolean isJarURI​(java.net.URI uri)
        Returns whether the given uri is a Jar URI as returned, e.g., by a classloader.
        Parameters:
        uri - the URI (ignored if null)
        Returns:
        true for a Jar URI, false else
      • isJarURL

        public static boolean isJarURL​(java.net.URL url)
        Returns whether the given url is a JAR URL as returned, e.g., by a classloader.
        Parameters:
        url - the URL (ignored if null)
        Returns:
        true for a JAR URL, false else
      • unpackJar

        public static void unpackJar​(java.net.URL url,
                                     java.io.File target)
                              throws java.net.MalformedURLException,
                                     java.io.IOException
        Unpacks a Jar file denoted by url to the given target folder. target may not exist and is created then. Existing files are overwritten.
        Parameters:
        url - the Jar URL
        target - the target folder
        Throws:
        java.net.MalformedURLException - in case that the URL is ill formed or not a Jar URL
        java.io.IOException - in case of any I/O problems
      • unpackJar

        public static void unpackJar​(java.net.URL url,
                                     java.lang.String resource,
                                     java.io.File target)
                              throws java.io.IOException
        Unpacks a Jar file denoted by url to the given target folder. target may not exist and is created then. Existing files are overwritten.
        Parameters:
        url - the Jar URL
        resource - a resource within the JAR to extract, may be a file or a folder in JAR format specification, i.e., without leading / but trailing /
        target - the target folder
        Throws:
        java.net.MalformedURLException - in case that the URL is ill formed or not a Jar URL
        java.io.IOException - in case of any I/O problems