Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials
  

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

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.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

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.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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

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

Copyright © 2007. All rights reserved.