Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read MANIFEST.MF inside WAR application?

Tags:

java

servlets

I would like to read MANIFEST.MF of my WAR application. How can I find its file name?

like image 929
yegor256 Avatar asked Nov 21 '10 18:11

yegor256


People also ask

What is manifest MF in war?

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.

How do I open manifest mutual fund?

I double-clicked the MANIFEST. MF file and it opened right up in Atom.

What does the manifest file do?

A MANIFEST file is an XML document that describes the manifest, or package contents, of a Windows software application. It is used by various Windows technologies for configuring and deploying software, including ClickOnce and the Common Language Runtime (CLR). MANIFEST files are often seen with the compound ".exe.


2 Answers

How can I find its file name?

You already have it. Maybe you meant to find the absolute file location? You can use ServletContext#getRealPath() for this.

String relativeWARPath = "/META-INF/MANIFEST.MF";
String absoluteDiskPath = getServletContext().getRealPath(relativeWARPath);
File file = new File(absoluteDiskPath);
// ...

Or if you want to get it as InputStream directly, use ServletContext#getResourceAsStream().

InputStream input = getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF");
// ...
like image 183
BalusC Avatar answered Oct 04 '22 20:10

BalusC


I had the same problem in every application and decided to create a component with a utility class in it: jcabi-manifests. Now it's easy to load any attribute from one of available MANIFEST.MF in classpath:

import com.jcabi.manifests.Manifests;
String value = Manifests.read("My-Version");

Also, check this out: http://www.yegor256.com/2014/07/03/how-to-read-manifest-mf.html

like image 31
yegor256 Avatar answered Oct 04 '22 22:10

yegor256