Confusion on Uses of Jar Manifest File

benz

I am reading packaging java applications with jar tool. I noticed a manifest file is created under META-INF directory. For a simple application, it felt like, it's serves no purpose. I searched on stackoverflow to understand the usages of Manifest file. I came across UsesOfManifestFile. While reading the answer, i got confused on point 2 and 3 which are :-

  1. What are download extensions? I am not able to understand the concept in the answer.
  2. What does it mean to seal the jar? It has given an example below like this

Name: myCompany/MyPackage/ Sealed: true

What is the use of putting such information? Can someone elaborate on these points. Thanks.

Levenal

The manifest file is like the guidance instructions for the java program to run the jar. When the manifest is created it will hold crucial information, for example a reference to the main program. When the java program runs your jar it doesn't know where to start, so it look sin the manifest for a line telling it where the class with the main method is so it has a start point for the program. Another use is a classpath line, which will tell the program where to find any 3rd party library's in the jar are, otherwise again, the java program won't find them.

There is a range of data that can be stored in the manifest file, I would recommend checking out the Oracle information on them and seeing if that clears it up a bit more.

EDIT: From the Oracle site regarding your example:

Packages within JAR files can be optionally sealed, which means that all classes defined in that package must be archived in the same JAR file. You might want to seal a package, for example, to ensure version consistency among the classes in your software.

You seal a package in a JAR file by adding the Sealed header in the manifest, which has the general form:

Name: myCompany/myPackage/ Sealed: true The value myCompany/myPackage/ is the name of the package to seal.

Note that the package name must end with a "/".

What this appears to mean is that any and all classes that you use in your program must be within the same jar file.

EDIT 2 (For comment response)

A manifest may contain the following line:

Main-Class: com.mkyong.awt.AwtExample  

When the javaw.exe (I think) runs your runnable jar, it has no idea where to start from, all java programs run via a main method, but if you have say 50 class files in your jar, it has no idea which one has the main method to start from. It will look at the manifest file, reads your above line and thinks right, the main method is in the package com.mkyong.awt and the class is AwtExample, it then finds this class and runs the program from that main method. It's most basic function within the jar is to tell the java program running the jar where to find the stuff it needs to run your jar.

Note: that example manifest entry came from a little tutorial which shows how to create a simple runnable jar.

Good Luck!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

uses-sdk not present in manifest file

From Dev

Reading manifest file: list <uses-library>

From Dev

Reading manifest file: list <uses-library>

From Dev

no main manifest attribute (But I have the manifest file in the jar)

From Dev

Exporting Jar file with Manifest attribute in Android Studio?

From Java

Replacing the MANIFEST.MF file in a JAR programmatically

From Dev

Using Java to read a .jar manifest file

From Dev

Jar command not adding requested manifest file to archive

From Dev

JAR Manifest file - Difference between Specification and Implementation

From Dev

JAR file manifest does not contain permission attribute

From Dev

Using Java to read a .jar manifest file

From Dev

add manifest to compiled exe file from jar

From Dev

"-includeresource" in JAR Manifest inside Gradle build file

From Dev

What jar file an import uses?

From Dev

Error opening zip file or JAR manifest missing : jrebel.jar

From Dev

How to configure a manifest file of a jar file by using the maven assembly plugin?

From Dev

Android 23 Not Generating Manifest file for uses-permission elements

From Dev

uses-sdk tag not showing on android manifest file

From Dev

What is the proper way to parse the entries of a manifest.mf file in jar?

From Dev

Failing to run jar file from command line: “no main manifest attribute”

From Dev

Error opening zip file or JAR manifest missing : C:\Program

From Dev

IOException: 'Invalid header field; when creating .jar file with manifest

From Dev

Java can't execute jar file no main manifest attribute

From Dev

"no main manifest attribute" after downloading a .jar file in Java

From Dev

Maven does not generate a MANIFEST file with maven jar plugin

From Dev

Open Source Jar file and Failed to load Main-Class manifest

From Dev

How to specify classpath loading order in a JAR manifest file

From Dev

How to repack a jar file with same manifest it had before?

From Dev

Add Classpath in Manifest file of jar in gradle in java 8

Related Related

  1. 1

    uses-sdk not present in manifest file

  2. 2

    Reading manifest file: list <uses-library>

  3. 3

    Reading manifest file: list <uses-library>

  4. 4

    no main manifest attribute (But I have the manifest file in the jar)

  5. 5

    Exporting Jar file with Manifest attribute in Android Studio?

  6. 6

    Replacing the MANIFEST.MF file in a JAR programmatically

  7. 7

    Using Java to read a .jar manifest file

  8. 8

    Jar command not adding requested manifest file to archive

  9. 9

    JAR Manifest file - Difference between Specification and Implementation

  10. 10

    JAR file manifest does not contain permission attribute

  11. 11

    Using Java to read a .jar manifest file

  12. 12

    add manifest to compiled exe file from jar

  13. 13

    "-includeresource" in JAR Manifest inside Gradle build file

  14. 14

    What jar file an import uses?

  15. 15

    Error opening zip file or JAR manifest missing : jrebel.jar

  16. 16

    How to configure a manifest file of a jar file by using the maven assembly plugin?

  17. 17

    Android 23 Not Generating Manifest file for uses-permission elements

  18. 18

    uses-sdk tag not showing on android manifest file

  19. 19

    What is the proper way to parse the entries of a manifest.mf file in jar?

  20. 20

    Failing to run jar file from command line: “no main manifest attribute”

  21. 21

    Error opening zip file or JAR manifest missing : C:\Program

  22. 22

    IOException: 'Invalid header field; when creating .jar file with manifest

  23. 23

    Java can't execute jar file no main manifest attribute

  24. 24

    "no main manifest attribute" after downloading a .jar file in Java

  25. 25

    Maven does not generate a MANIFEST file with maven jar plugin

  26. 26

    Open Source Jar file and Failed to load Main-Class manifest

  27. 27

    How to specify classpath loading order in a JAR manifest file

  28. 28

    How to repack a jar file with same manifest it had before?

  29. 29

    Add Classpath in Manifest file of jar in gradle in java 8

HotTag

Archive