我想显示部署在同一服务器上的Web应用程序中的jboss eap服务器中部署的所有工件名称及其实现版本详细信息。如何从另一个Web应用程序中的war文件读取清单文件。
sce.getServletContext()。getResourceAsStream(“ / META-INF / MANIFEST.MF”);仅可从war servlet上下文中获取清单文件。
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();
}
}