-4

I have a jar file named "mail.jar" .I have extracted the jar file through java code. Now I have manifest file present under "D:/Test/META-INF/MANIFEST.MF" location.This is the image of Manifest.mf file content. Any way I am able to read to Manifest file by the help of FileReader and BufferedReader and print it to the console. In the manifest file ,below specifications r present. (1)Manifest-Version: (2)Archiver-Version: (3)Created-By: (4)Export-Package:

Now my doubt is how to get all the package list under Export-Package: tag only . Can anyone help me here ?? Any help will be appreciated.

O/P should display like below screen shot. Expected O/P screen shot

Regards, AD

Abinash
  • 37
  • 10
  • Please rephrase your question. It is unclear what you want to do or need. – Tzach Solomon Sep 18 '16 at 07:50
  • Solomon,Are you getting my requirement here now ? Plz let me know if any doubts you have to under stand the question ... – Abinash Sep 18 '16 at 07:59
  • 1
    Probably with the [Manifest](https://docs.oracle.com/javase/7/docs/api/java/util/jar/Manifest.html) class. Create an object with an input stream from your manifest file. – PeterMmm Sep 18 '16 at 08:19
  • 1
    You can read the manifest file if you use the java.util.jar.JarFile and than call getManifest(). From than, use getMainAttributes().getValue('Export-package') and split that string using .split(',') – Tzach Solomon Sep 18 '16 at 08:39
  • Sorry but can you clarify your question? Do you have problem with *accessing* manifest file, or with *parsing* it? Also how does your code look like? – Pshemo Sep 18 '16 at 08:57
  • Peshmo,this is regarding facing problem in accessing specific attribute of manifest file content. – Abinash Sep 18 '16 at 10:31

1 Answers1

1

Hi solomon & PeterMmm, Thanks for your help. now I am able to access the manifest file content for specific attribute. Below is the code snippet I am using:-

public class ReadmanifestFile {
public String getManifestAttributes() throws IOException {
    String value = null;
    File file = new File("G:/AD/JAR_FILES/mail.jar");
    if (file.isFile()) {
        JarFile jarfile = new JarFile(file);
        Manifest manifest = jarfile.getManifest();
        Attributes attributes = manifest.getMainAttributes();
        value = attributes.getValue("Export-Package");
        String[] arr = value.split(";");
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
    return value;
}

}

click the below for Output for above code snippet:- Output

I think this is right way to do.Plz let me know if I can improve the code snippet in any of the other ways.

regards, AD

Abinash
  • 37
  • 10