Tomcat 7 - 检索 web 应用程序的版本(版本化 WAR)

2024-01-06

我一直无法找到任何简单的方法来确定使用 Tomcat 7 版本命名部署的 WAR 文件的版本字符串(即 app##version.war)。你可以阅读相关内容here http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming以及它能带来什么here http://www.javacodegeeks.com/2011/06/zero-downtime-deployment-and-rollback.html.

除了通常的瑞士军刀反射驱动的胸腔破裂之外,如果有一种更受支持的方法那就太好了:

final ServletContextEvent event ...
final ServletContext applicationContextFacade = event.getServletContext();
final Field applicationContextField = applicationContextFacade.getClass().getDeclaredField("context");
applicationContextField.setAccessible(true);
final Object applicationContext = applicationContextField.get(applicationContextFacade);
final Field standardContextField = applicationContext.getClass().getDeclaredField("context");
standardContextField.setAccessible(true);
final Object standardContext = standardContextField.get(applicationContext);
final Method webappVersion = standardContext.getClass().getMethod("getWebappVersion");
System.err.println("WAR version: " + webappVersion.invoke(standardContext));

我认为最简单的解决方案是使用相同的版本(SVN 修订+填充作为示例).war, web.xml and META-INF/MANIFEST.MF属性文件,以便您稍后可以在应用程序或任何从 JAR/WAR 读取版本的标准工具中检索这些文件的版本

See 清单.MF版本号 http://docs.oracle.com/javase/1.5.0/docs/guide/jar/jar.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Tomcat 7 - 检索 web 应用程序的版本(版本化 WAR) 的相关文章

随机推荐