I have a application that runs as war or in standalone mode with tomcat embedded, I want to check if the application is running as a war within tomcat or if it is running with tomcat embedded.
This is my solution.
String path = getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
boolean onWar = path.contains("WEB-INF");