I would like to read MANIFEST.MF
of my WAR
application. How can I find its file name?
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.
I double-clicked the MANIFEST. MF file and it opened right up in Atom.
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.
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");
// ...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With