I would like to display all the artifact name along with its implementation version details deployed in an jboss eap server in a web application deployed in same server.How can i read the manifest file from a war file in another webapplication.
sce.getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"); works only to get the manifest file from the war servlet context.
public class Version implements ServletContextListener {
private static final Logger LOG = LoggerFactory.getLogger(Version.class);
private static Attributes sMainManifestAttributes;
public static final String ARTIFACT_ID = "Implementation-Title";
public static final String ARTIFACT_VERSION = "Implementation-Version";
/**
* Read the manifest from /META-INF/MANIFEST.MF
*/
@Override
public void contextInitialized(ServletContextEvent sce) {
try {
ServletContext application = sce.getServletContext();
InputStream inputStream = application.getResourceAsStream("/META-INF/MANIFEST.MF");
Manifest manifest = new Manifest(inputStream);
sMainManifestAttributes = manifest.getMainAttributes();
LOG.info("BIH Artifact Name:" + sMainManifestAttributes.getValue(ARTIFACT_ID) + " Artifact Version :"
+ sMainManifestAttributes.getValue(ARTIFACT_VERSION));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
sMainManifestAttributes = null;
}
/**
* Generic querying of the manifest.
*
* @return The result, as run through String.trim()
*/
public static String getValue(String name) {
return sMainManifestAttributes.getValue(name).trim();
}
}