Atharva
Atharva

Reputation: 6969

Changing property values while redeploying new version of .war in tomcat

In my Java web application where I am using tomcat as my app server, I am interested in a way of passing different value to a particular property to the application when it is deployed/redeployed.
There are several ways that I am aware of:

  1. One is through JVM options passed to the tomcat set in setenv.sh file. Requires server to be restarted for each redeployment as far as I know.
  2. To specify the property values in properties file. Requires the values set manually by hand in the file and rebuilding the application before each redeployment of the same version of the application.
  3. While using spring, specifying the property value in some bean defined in the applicationContext.xml file. Again requires manual approach and app rebuilding.
  4. Storing configuration in the database. This requires that we know the connection properties for the database storing such configurations.

Now if I plan to change certain property variable such as an IP address, number of connections, port number or some other such variable every time deploying/redeploying the app, what strategy should I follow? Is there a popular well accepted way of passing such property values to web application deployed in tomcat? Is it necessary to restart the tomcat server if I pass the property value as JVM options?

Or is there any other generic way for configuring the deployment parameters that I have not mentioned above? I would prefer a process which can easily be automated to be done programmatically(like passing JVM options), instead of setting properties by hand before each deployment(like setting properties file). It should also not require the rebuild of same version each time before redeployment.

Upvotes: 2

Views: 1071

Answers (1)

mindas
mindas

Reputation: 26713

I think JNDI was invented for exactly the purpose you are asking for:

  • you don't have to modify JVM options
  • you don't have to restart Tomcat every time you change these options
  • you don't have to rebuild your app
  • you can change these values externally/programmatically. I believe Tomcat allows that, or even if not - it shouldn't be hard to write something like settable MBean which would set the relevant property(ies) through JMX

Upvotes: 1

Related Questions