views:

394

answers:

4

Hi All,

Our project is a medium size web application developed using RAD 7.0 on WAS 6.1/hibernate/struts which moved to production. Currently we have hardcoded the ip address of the production system in the property file and database schema details in the hibernate config file.

Our client wants us to come up with the solution for keeping the environment details out side the EAR, so that they can change the environment/db details in future with out opening the EAR .

Any pointers would be very helpful. Thanks.

+2  A: 

You can use JNDI for this. You should create the appropriate entries and in your code read them like this:

Context initialContext = new InitialContext();
URL ip = (URL) initialContext.lookup("java:comp/env/myip");

See this article on how to use a JNDI Data Source in hibernate configuration files.

kgiannakakis
Definitely use JNDI for the database and then use the database for any other properties. External property files aren't terrible for a single instance but if you ever want to cluster, it becomes a mess to keep them all in sync.
Brian Deterling
What about reading String values and/or IP addresses directly from JNDI?
kgiannakakis
A: 

You can try these, I stick to the first solution in my projects.

  1. Have all this info in a property file which is bundled inside EAR. When ever they want to change the info, they have to re-deploy the EAR. This is what I use as that way we can do the change controll in SCM.

  2. Make your application read a property file which have these details and at the time of application start the code refers to this file which is outside of EAR. They change the data and restart the application.

Bhushan
A: 

You could maintain the configuration in a directory outside the ear on the server and when the application starts (typically using a servlet that is invoked on application start up), read the configuration into a singleton or a static class. Provide a utility to the admin user in the application to reload the configuration from the file so that whenever there is a change in the latest configuration can be reloaded.

Shyam
A: 

i got one answer from other forum that using class path setting which is available in web server setting we can do this

specify the directory path where u have stored the property file and restart the server thats it

but have to try this

is any way to move the hibernate cfg file out of the EAR or just db configuration details which we mention in hibernate cfg out side the EAR?