0

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.

Henrique Luiz
  • 191
  • 1
  • 12
  • May be this helps : https://stackoverflow.com/questions/3890504/how-to-check-if-tomcat-runnning-using-embedded-tomcat – harp1814 Jun 13 '19 at 19:19
  • Sorry I don't want to check if Tomcat is online but what Tomcat is running. – Henrique Luiz Jun 13 '19 at 19:35
  • If You know where the application is running, You can grep through list of processes and find tomcat. Should You see `catalina` in the process command, then its probably standalone tomcat. You can also check if Your application is in `webapps` directory in tomcat location. – Michal W Jun 13 '19 at 19:54
  • A bit generic question, do you want to know from the OS, from inside the app? – LMC Jun 14 '19 at 00:02
  • 1
    If all is under your control the safe way is to add a parameter at starting `java -Druns.embedded ...` o similiar and retrieve/check in your code. – PeterMmm Aug 05 '19 at 11:30

1 Answers1

1

This is my solution.

String path = getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
boolean onWar = path.contains("WEB-INF");
Henrique Luiz
  • 191
  • 1
  • 12