【问题标题】:WAR, manifest.mf and versionWAR、manifest.mf 和版本
【发布时间】:2014-02-20 12:15:18
【问题描述】:
我有一个 WAR 文件,并且在 /META-INF/MANIFEST.MF 中包含我的产品版本信息:
Implementation-Version: 1.0.0.0
在我的 index.jsp 我有这个代码来打印版本:
<%
String version = com.my.Utils.class.getPackage().getImplementationVersion();
out.print("Version: " + version);
%>
这段代码总是返回:
Version:
此解决方案基于this article。
我需要从战争清单文件中读取我的版本信息吗?
【问题讨论】:
标签:
java
version
manifest
war
【解决方案1】:
您链接的那篇文章特别提到了第二种情况,您正在部署一个经典的 Web 应用程序:
<%
//Get version of application
java.util.Properties prop = new java.util.Properties();
prop.load(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"));
String applVersion = prop.getProperty("Implementation-Version");
%>
<h2 class="x-panel-header"><%=applVersion%></h2>
方法因应用程序的部署方式而异。