Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Listing the Main Attributes in a JAR File Manifest 
 

This section describes the main attributes in a JAR file manifest in java program.

 

Listing the Main Attributes in a JAR File Manifest

                         

Jar Manifest: Jar Manifest file is the main section of a jar file. This file contains the detailed information about the specific individual jar file. It contains the complete information about the jar file, each and every section or particular information is separated by new line. For mentioning information in the manifest file you have to maintain the information syntax with rule and restrictions.

Main Attributes in Jar file are these attributes which are applied for each and every individual manifest file for entry. This section, in which these attributes are defined, contains jar configuration and security information. This section is terminated by new empty line.

An individual section of the manifest file contains the list of the information about packages and files which are to be signed. There not need to list all the files of the jar file. The manifest file itself not nee to be listed. Every section starts with the name of attributes and values of these attributes. Attributes and values are separated with colon (":"). Values of the attributes are mentioned according to the attributes like relative path to the path, an absolute URL for archiving data from outside.

Program Result:

Following program is given for the best illustration of the jar manifest file. This program takes a jar file which manifest file content has to be shown and helping you to show the main attributes and values of all attributes mentioned in the manifest file. It checks for the file format (for the jar format) and it also checks whether the file exists or not.

Here is the code of the program:

import java.util.*;
import java.util.jar.*;
import java.io.*;

public class MainJarAtr{
  public static void main(String[] args){
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    try {
      System.out.print("Enter jar file name: ");
      String filename = in.readLine();
      if(!filename.endsWith(".jar")){
        System.out.println("File not in jar format.");
        System.exit(0);
      }

      File file = new File(filename);
      if (file.exists()){
        // Open the JAR file
        JarFile jarfile = new JarFile(filename);

        // Get the manifest
        Manifest manifest = jarfile.getManifest();

        // Get the main attributes in the manifest
        Attributes attrs = (Attributes)manifest.getMainAttributes();

        // Enumerate each attribute
        for (Iterator it=attrs.keySet().iterator(); it.hasNext()) {
          // Get attribute name
          Attributes.Name attrName = (Attributes.Name)it.next();
          System.out.print(attrName + ": ");
          
          // Get attribute value
          String attrValue = attrs.getValue(attrName);
          System.out.print(attrValue);
          System.out.println();
        }
      }
      else{
        System.out.print("File not found.");
        System.exit(0);
      }
    }
    catch (IOException e) {}
  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c com make this ie example to exam pic top e it complete in as sta m let pi xa

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.