How to read MANIFEST.MF inside WAR application?
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
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");
// ...