Java Jar Usage getInfo(String jarFileName)

Here you can find the source of getInfo(String jarFileName)

Description

Util: gets information about the given jar file name

License

Apache License

Parameter

Parameter Description
jarFileName file name of the jar file to get information

Declaration

public static void getInfo(String jarFileName) throws Exception 

Method Source Code

//package com.java2s;
/*/*w  w w.j a  v  a2 s  .c  o  m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 * Copyright (C) 2006-2010 Adele Team/LIG/Grenoble University, France
 */

import java.util.Date;
import java.util.Enumeration;

import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class Main {
    /**
     *  Util: gets information about the given jar file name
     *
     * @param  jarFileName    file name of the jar file to get information
     * @exception  Exception  an exception occurs
     */
    public static void getInfo(String jarFileName) throws Exception {
        // Create a Jar file.
        JarFile jarFile = new JarFile(jarFileName);

        System.out.println("\n---------------------------------------------------------");
        System.out.println("Information about the jar file: " + jarFileName);
        System.out.println("---------------------------------------------------------");

        // Get all of the Jar entries.
        Enumeration jarEntries = jarFile.entries();

        // Print out information.
        JarEntry currentJarEntry = null;
        while (jarEntries.hasMoreElements()) {
            currentJarEntry = (JarEntry) jarEntries.nextElement();

            System.out.println();
            if (currentJarEntry.isDirectory())
                System.out.println("Directory = " + currentJarEntry.getName());
            else
                System.out.println("File = " + currentJarEntry.getName());
            System.out.println("\tcomment = " + currentJarEntry.getComment());
            System.out.println("\ttime = " + new Date(currentJarEntry.getTime()));
            System.out.println("\tsize = " + currentJarEntry.getSize());
            System.out.println("\tcompress size = " + currentJarEntry.getCompressedSize());
            System.out.println("\tcrc = " + currentJarEntry.getCrc());
        }

        // Fermeture du fichier jar
        jarFile.close();
    }
}

Related

  1. findClassesByJar(String packageName, JarFile jar, final boolean recursive, Set> classes)
  2. getAttribute(String name, String value)
  3. getClassNameByJar(String jarPath, boolean childPackage)
  4. getEntriesName(String jarFileName)
  5. getFileNamesWithSuffixForJarFile(JarFile jar, String suffix)
  6. getJarInFileList(JarFile jarFile, String targetPath)
  7. getMatchingResourcesFromJar(JarFile jarFile, String suffix)
  8. getSortedAttributes(Attributes mainAttributes)
  9. getSortedJarEntries(JarFile jarFile)