spring-boottomcatwarcatalina

Different Java Args per application in Shared Tomcat Server


I'm deploying two spring servlets in a shared tomcat environment. I'd like to be able to run each application with its own command line args. An example would be, I want to run each one with a different spring profile active. I know I can set an environment variable in setenv.sh, but I want to make this dynamic. I had thought I could do an if/else in the catalina.sh, if the app name is X then set args accordingly. Could I use an environment variable which my application picks up & set the profile from here? Does anyone know how this could be achieved? I don't want to change the build of the application, and I don't want to make global changes that would impact other applications in this shared tomcat server.

I have tried setting an if/else in catalina.sh where the JAVA_OPTS are being set, but this isnt set for each application, rather it's set globally. I want to be able to change where the war is automatically deployed from.


Solution

  • It may not be perfect, but it works for me:

    I've created environment variables for each application, and read these in the each application's properties files. In the example Application-A and Application-B, which need to be run with two different spring profiles.

    in setenv.sh

    export PROJECT-A_SPRING_PROFILE="develop"
    export PROJECT-B_SPRING_PROFILE="prod"
    

    and in each application's properties file I refer to these, i.e. spring.profiles.active=${PROJECT-A_SPRING_PROFILE:#{default}} and spring.profiles.active=${PROJECT-B_SPRING_PROFILE:#{default}} respectively