如何检查应用程序是否在 Tomcat 7 嵌入式上 运行?

How to check if app is running on Tomcat 7 embedded?

我有一个应用程序以 war 或独立模式运行并嵌入 tomcat,我想检查该应用程序是否 运行 作为 war tomcat 或者如果它是 运行 tomcat 嵌入式。

这是我的解决方案。

String path = getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
boolean onWar = path.contains("WEB-INF");