Tomcat 7 - 检索webapp的版本(版本化的WAR)

Mår*_*son 4 versioning version war tomcat7

我一直无法找到任何简单的方法来计算使用Tomcat 7版本化命名部署的WAR文件的版本字符串(即app ## version.war).你可以阅读有关它在这里,什么它使这里.

如果除了通常瑞士军刀的反射动力肋骨开裂之外还有一些更受支持的方法,那就太好了:

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));
Run Code Online (Sandbox Code Playgroud)

gav*_*oto 5

我认为,最简单的办法是使用相同的版本(SVN版本+填充为例).war,web.xmlMETA-INF/MANIFEST.MF属性文件,所以你可以在你的APP或任何标准的工具,从一个JAR/WAR阅读版本以后检索这些文件的版本

请参阅MANIFEST.MF 版本号