Listing the Main Attributes in a JAR File Manifest

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

Ads

Tutorials   
How to read properties file in Java? Generate random numbers in Java Cloneable Interface in Java What is the flaw with the Stack class? List In Java Java Stack Example HashSet In Java Enumeration in java How to generate random number in java Iterator in java Queue in java Transient Java Keyword clone method in Java Java Queue example Logger in Java Java current date - How to get current date in Java Collection : LinkedList Example Collection : ArrayList Example Random alpha numeric string of fixed size Java List Iterator Example The Hashtable Class The BitSet class Java Vector Java Enumeration Data Structures in Java Java Transient Variable Java Date Format Example Java Properties File Example Map.Entry Java Interface Java Property File java preferences,Change the value of Preferences by user Retrieving a Preference Node Java hasNext Write Keys and Values to the Properties file in Java Get All Keys and Values of the Properties files in Java Properties file in Java Properties file in Java Determining If a Preference Node Contains a Specific Value Change the value of Preferences by user Clone method example in Java Implementing a Simple Event Notifier Determining When a Preference Node Is Added or Removed Listening for Changes to Preference Values in a Preference Node Importing Preferences Finding a Preference in a Preference Tree Retrieving the Parent and Child Nodes of a Preference Node Determining If a Preference Node Exists Removing a Preference Node Creating a Preference Node Getting the Maximum Size of a Preference Key and Value
Ads

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.

Advertisements

Share on Google+Share on Google+

Listing the Main Attributes in a JAR File Manifest

Posted on: April 16, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Listing the Main Attributes in a JAR File Manifest  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads