What is use of MANIFEST.MF in WAR/JAR/EAR?
Asked Answered
F

1

23

I am aware of usage of MANIFEST file in a mobile application, but am not aware of usage of same in a Java Application.

My guess say like, its being used to keep BUILD information only. Am I correct??

Is this Mandatory?If not, then what are the key benefits that we can draw with this?

Facelifting answered 21/6, 2012 at 13:48 Comment(1)
for example, you can use it for versioning, as explained here: jcabi.com/jcabi-manifests/versioning.htmlMainland
P
20

manifest.mf carries attributes of the artifact. One of the most well known ones is for example the main class of the jar that is used to start the jar file when no other class is specified. Syntax:

Main-Class: classname

Other purposes are, for example, package sealing and package versioning. Check out the java tutorial about it: http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html

A manifest in a jar usually contains much less information than for example AndroidManifest.xml. It is quite lightweight and does not contain any build or packaging information.

This is because java has no good module system. So, a jar is not a module which might need a lot of configuration information (like a list of modules to which it has dependencies). Instead, a jar is just a bunch of classes with some configuration information. Hopefully, this will be fixed by project jigsaw (http://openjdk.java.net/projects/jigsaw/).

Print answered 21/6, 2012 at 13:51 Comment(7)
Right now My manifest file is like "Manifest-Version: 1.0" only. Still my application is doing fine.Facelifting
of course, the mainfest is not necessary. It is simply able to carry additional information about the jar.Print
I would like to draw a comparison here, Like in Mobile application, the application would not run without it, but that's not the case with Jar etc why?Facelifting
Simple answer: It is not required by the java programming language :). What mobile platform are you talking about?Print
Like for Andriod, we have to mention what kind of resource the application is intended to use, if we dont declare it, we will not be able to run the application on a mobile.I might be wrong but am just trying to draw some comparison.Facelifting
what are the key benefits that we can draw with this?Facelifting
not too many. Unless you need exactly one of the things described in the tutorial, you won't need to think about writing a manifest. In comparsion with android, it is much more lightweight, it contains only some optional configuration information, not much more.Print

© 2022 - 2024 — McMap. All rights reserved.