java - 如何从战争应用程序中获取 manifest.mf 文件
问题描述
我想显示所有工件名称及其部署在 jboss eap 服务器中部署在同一服务器中的 web 应用程序中的实现版本详细信息。如何从另一个 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();
}
}
解决方案
推荐阅读
- reactjs - 使用 Chartjs 对堆积条形图有什么作用
- parallel-processing - GNU Parallel 不会在所有文件上运行
- javascript - 使用 swipper.js 引导 4 张卡片
- c# - 从 JsonConvert 反序列化 JSON 对象返回 null
- java - while 语句没有在 if 语句中执行?
- javascript - NextJS 中的环境变量未定义
- google-chrome-extension - 为什么在 MacOS 上的 Greasemonkey/Tampermonkey 上的本地脚本,@require 总是给我错误“无法从禁止的 URL 加载 @require”
- python - 在 Jupyterhub 中安装 R
- angular - 为什么服务获取 id 总是“未定义”?
- python - python和jupyter笔记本中的模块位置不一致