I was unable to find any easy way to figure out the version string for the WAR file deployed with the Tomcat 7 name version (e.g. app ## version.war). You can read about it here and what it allows here .
It would be nice if there was a slightly more supported approach, different from the usual Swiss army knife with reflex feed on the chest:
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));
source share