Search code examples
javamavenconfigurationejbweblogic

How to dynamically load server configurations depending on server/environment?


Currently I setup maven profiles to be able to deploy my project for different environments (dev, demo, staging, production, ...) and it works perfectly fine. But the issue is that for each module (web application) that I have, I need to copy/paste this configuration files ( they are all property files). This will be an overhead when I need to change an environment/server configuration (for example when a port number changes I need to redeploy all my EAR files).

My question is, is there any more generic solution to prevent from such redundant approach? for example to set up my property files (or any other configuration file) in weblogic? I came up with a small module to keep the configurations and call them via @Remote (EJB) but that has lots of other drawbacks base on my organization's applications relationships.

So best approach for me could be to be able to setup some configurations in weblogic and get access to them dynamically when the application is running and then decide base on that.


Solution

  • There is an alternative solution that I came up with and I think it better works for me and my organization.

    I will have a JAR that stands between the client (developer) and system. So that the JAR will read from a .properties file (or any file) which is defined as environment variable inside the server (each server will adopt its own settings). Then inside the JAR, I read the file and will return the requested values. This will let developers just focus on their code and they can call getCurrentServer() or getServer(XXX) from the JAR (considering that appropriate exception handling is important).

    Existing modules should be updated and redeployed. The only drawback for this implementation would be if I change the .properties file, then I need to restart the server, Because the file loading mechanism will be just once (implementing singlton pattern) for better performance. Anyways, I don't think it is a big deal, because that file might change very rarely (at most once a year or once in two years), so it does worth to restart the server (or I can load the file any time the client requested so that there is no need to restart the server - but it will have bad impact on performance -).

    - update I implemented another method to access the private method of the JAR and call loadProperties() method. By doing this, I can manually reload the properties without restarting the server.