Jar package merger

Jar Jar package package is about to merge files into a new summary Jar package, including the original package and extract Jar Jar package and generate a new two-step.

Jar recommended compression tool to open the package, the META-INF Jar package removed, no effect on the reading dependent, and when extracting the files inside, together with the name of coverage.

Jar decompressed packet, generates the jar.exe requires the use of tools, this tool in the JDK bin. After configuring the JDK environment variable cmd directly using the jar command.

Check the jar command:
C: \ the Users \ hao> jar
Usage: jar {ctxui} [vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Options:
    -c create the new archive
    -t list the archive directory
    -x extract the specified (or all) files from archive
    -u update existing archive
    -v generate verbose output on standard output
    -f specify archive file name
    -m containing the specified manifest file inventory information
    to perform Pack200 normalization after you create a new file -n
    -e is tied to a separate application executable jar file
        specified application entry point
    -0 store only; do not use any ZIP compression
    -P reserved file names of the leading '/' (absolute path) and ".." (parent directory) components
    -M do not create a manifest file entry
    -i generate index information for the specified jar file
    -C change to the specified directory and contains the following files
if any file is a directory, its recursive processing.
List of file names, file names and file order specified entry point name
and 'm', 'f' and 'e' of the same tag sequence designated.

Example 1: The two class files to the archive file named in classes.jar:
       JAR CVF classes.jar Foo.class Bar.class
Example 2: Use existing file 'mymanifest' and
           the foo / directory All files archived to 'classes.jar' in:
       JAR CVFM classes.jar mymanifest--C foo /.
       
the combined steps of:
(1) the Jar decompression:
extracting Jar package command: jar -xvf Jar package original name (with suffix)
this command must first cd to the directory Jar package.
Here jar -xvf * .jar unavailable. Each Jar package rely on command corresponding decompression, a lot of trouble. Recommends that all Jar package into a single new directory. Then extract the centralized command.
Enter filePath in your new directory, run the following code, unzip command to get all the Jar package:

import java.io.File;

public class DealJarFolder {
    public static void main(String[] args){
        String filePath = "C:\\Users\\hao\\Desktop\\libs";
        searchJarName(filePath);
    }

    private static void searchJarName(String filePath){
        File folder = new File(filePath);
        File[] fileArray = folder.listFiles();
        if(folder.isDirectory()){
            for(int i = 0;i < fileArray.length;i++){
                File file = fileArray[i];
                String fileName = file.getName();
                if(file.isDirectory()){
                    searchJarName(filePath + "/" + fileName);
                }

                if(file.isFile()){
                    if(fileName.indexOf(".jar") != -1){
                        System.out.println("jar -xvf " + fileName);
                    }
                }
            }
        }
    }

}

After Jar cd to the directory packet, the resulting command can be pasted into the cmd. The reason newline character will automatically run other packages except the last Jar Jar unpack command a decompression command. Before the end of the decompression, decompression and then Enter will last about a Jar package. Of course, use 360 or WinRAR compression select multiple (using Ctrl or Shift keyboard shortcut), right-extract to the current folder is required.
(2) In order to unpacked in the new directory merge files into a new package Jar, Jar package need to delete the original. Select multiple (using Ctrl or Shift keyboard shortcut) or by deleting command. Of course, if you unzip the file into a new blank directory in the directory merge can unzip files.
Delete Jar package command: del / F * .jar
(3) generate a new package Jar:
New Jar packet generation command:. Jar -cvfM new Jar package name (suffix)
that must first cd command to unpack the original Jar file storage directory.
Note: The last command to point to end.

reference:

https://www.cnblogs.com/029zz010buct/p/4882568.html

https://www.cnblogs.com/wangshuo1/p/5697746.html

Guess you like

Origin blog.csdn.net/haoranhaoshi/article/details/94733273
Recommended