How do I run multiple instances war in one Liberty Server?

1.1k Views Asked by At

I have an application running as war in Liberty Server. How do I have the multiple instances of the same run in Liberty Server? Is there a way to get the name of the war inside the java code?

String completePath=getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath();

returned .../target/classes. No war file name.

1

There are 1 best solutions below

7
On

You should be able to specify multiple <webApplication ...> elements in the server.xml with different values for the "id", "name" and "contextRoot" attributes, but specify the same "location" attribute (pointing to the actual WAR file).

As for getting the name of the WAR from the Java code, you could try using the ServletContext APIs like getServletContextName() or getContextPath() to differentiate between the multiple instances. More info in the javadoc here: https://www.openliberty.io/docs/20.0.0.10/reference/javadoc/liberty-javaee8-javadoc.html#javax/servlet/package-summary.html&class=javax/servlet/ServletContext.html&package=allclasses-frame.html