Class JARTool


  • public class JARTool
    extends java.lang.Object
    JAR toolbox
    This class only provides static variables and methods
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String MANIFEST_PATH
      Manifest fie path in a JAR
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void add​(java.io.File jar, java.io.File file, java.lang.String pathInJar)
      Add a File to a JAR.
      static void addManifest​(java.io.File jar, java.lang.String manifest)
      Add a manifest to a JAR.
      static java.lang.String content​(byte[] data)
      Get JAR content
      static java.lang.String content​(java.io.File file)
      Get JAR content
      static java.lang.String content​(java.io.InputStream in)
      Get JAR content
      static java.lang.String content​(java.lang.String path)
      Get JAR content
      static void create​(java.io.File file, java.lang.String dir, java.lang.String[] pkgs)
      Create jar from directory
      static void create​(java.io.OutputStream out, java.lang.String dir, java.lang.String[] incs)
      Create jar from directory
      static byte[] create​(java.lang.String dir)
      Create jar from directory
      static byte[] create​(java.lang.String dir, java.lang.String[] pkgs)
      Create jar from directory
      static void create​(java.lang.String path, java.lang.String dir, java.lang.String[] pkgs)
      Create jar from directory
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MANIFEST_PATH

        public static final java.lang.String MANIFEST_PATH
        Manifest fie path in a JAR
        See Also:
        Constant Field Values
    • Method Detail

      • content

        public static java.lang.String content​(java.lang.String path)
                                        throws java.io.IOException
        Get JAR content
        Parameters:
        path - JAR file path
        Throws:
        java.io.IOException
      • content

        public static java.lang.String content​(java.io.File file)
                                        throws java.io.IOException
        Get JAR content
        Parameters:
        file - JAR file
        Throws:
        java.io.IOException
      • content

        public static java.lang.String content​(byte[] data)
                                        throws java.io.IOException
        Get JAR content
        Parameters:
        data - JAR data
        Throws:
        java.io.IOException
      • content

        public static java.lang.String content​(java.io.InputStream in)
                                        throws java.io.IOException
        Get JAR content
        Parameters:
        in - JAR input stream
        Throws:
        java.io.IOException
      • create

        public static byte[] create​(java.lang.String dir)
                             throws java.io.IOException
        Create jar from directory
        Parameters:
        dir - Directory
        Throws:
        java.io.IOException
      • create

        public static byte[] create​(java.lang.String dir,
                                    java.lang.String[] pkgs)
                             throws java.io.IOException
        Create jar from directory
        Parameters:
        dir - Directory
        pkgs - Optional list of packages to include (defaults to all files/directories)
        Throws:
        java.io.IOException
      • create

        public static void create​(java.lang.String path,
                                  java.lang.String dir,
                                  java.lang.String[] pkgs)
                           throws java.io.IOException
        Create jar from directory
        Parameters:
        path - JAR file path
        dir - Directory
        pkgs - Optional list of packages to include (defaults to all files/directories)
        Throws:
        java.io.IOException
      • create

        public static void create​(java.io.File file,
                                  java.lang.String dir,
                                  java.lang.String[] pkgs)
                           throws java.io.IOException
        Create jar from directory
        Parameters:
        file - JAR file
        dir - Directory
        pkgs - Optional list of packages to include (defaults to all files/directories)
        Throws:
        java.io.IOException
      • create

        public static void create​(java.io.OutputStream out,
                                  java.lang.String dir,
                                  java.lang.String[] incs)
                           throws java.io.IOException
        Create jar from directory
        Parameters:
        out - Output stream
        dir - Directory
        incs - Optional list of directories/packages or files to include (defaults to all files/directories)
        Throws:
        java.io.IOException
      • add

        public static void add​(java.io.File jar,
                               java.io.File file,
                               java.lang.String pathInJar)
                        throws java.io.IOException
        Add a File to a JAR.
        Parameters:
        jar - JAR file
        file - File to add
        pathInJar - Path of file in JAR (if null use plain file name)
        Throws:
        java.io.IOException
      • addManifest

        public static void addManifest​(java.io.File jar,
                                       java.lang.String manifest)
                                throws java.io.IOException
        Add a manifest to a JAR.
        Parameters:
        jar - JAR file
        manifest - Manifest content
        Throws:
        java.io.IOException