permaculture playing cards*
The moose likes Other Application Frameworks and the fly likes keeping properties file out of war Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "keeping properties file out of war" Watch "keeping properties file out of war" New topic
Author

keeping properties file out of war

Angelo Mario Del Grosso
Greenhorn

Joined: Apr 27, 2010
Posts: 3
We've got a Seam app doing all the usual things with datasources. Notably, pulling datasource info (url, username, password, etc.) from a separate property file.

Is there a way to store and source .properties file outside of the .war? If I've got this right, Seam assumes the "root" of the paths used are the root of the .war?

But that's a bummer since installing on a new server (with a different database) means have to explode the .war just to edit the datasource-config file.

How do you guys handle this situation? Or do you just live with having to explode the .war to make config edits?

Thanks!

Angelo Mario
Joachim Rohde
Ranch Hand

Joined: Nov 27, 2006
Posts: 423

I'm having different Maven-profiles with different configurations for different environments.
So, if you are using Maven as your build-tool, have a look at http://maven.apache.org/guides/introduction/introduction-to-profiles.html
Angelo Mario Del Grosso
Greenhorn

Joined: Apr 27, 2010
Posts: 3
Thanks,

Is not a build problem, but after it was made! I have to read several configuration values from a file keeping out of war! It is possible?

I'm not using maven!

other suggestions?

Joachim Rohde wrote:I'm having different Maven-profiles with different configurations for different environments.
So, if you are using Maven as your build-tool, have a look at http://maven.apache.org/guides/introduction/introduction-to-profiles.html
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Angelo,

i know the problem you're talking about exactly I'm still not sure what would be the best way to externalize such configuration properties completely to be able to deploy the same WAR file on any server without having to modify the content of the WAR itself.

I guess one clean way would be to use a JNDI lookup inside your application in order to retrieve database configuration parameters etc. Every application server or servlet container offers a way to provide information via JNDI lookups to applications running inside of it.

So you could always use the same JNDI lookup key (e.g. "jdbc/yourDatabase") inside your application and configure the container/server to provide the correct information via this key. This way you don't have to modify the application itself but instead you use the application server facilities to configure which information should be provided via this lookup key. This should be enough for typical use cases I think. For example if you have an application server for testing you usually want to use a test database together with it. From your application's view this doesn't make any difference because the JNDI key would be the same. All that you or an administrator would have to do is to configure the application server to provide configuration parameters for the correct database etc.

I hope this was more or less clear

But I'm sure there are other ways to configure a web application without having to modify the application itself. Even though Maven profiles would be a solution to easily build different WARs I'd still be interested to hear about other ideas.

Marco
Angelo Mario Del Grosso
Greenhorn

Joined: Apr 27, 2010
Posts: 3
Hi Angelo,

i know the problem you're talking about exactly I'm still not sure what would be the best way to externalize such configuration properties completely to be able to deploy the same WAR file on any server without having to modify the content of the WAR itself.

I guess one clean way would be to use a JNDI lookup inside your application in order to retrieve database configuration parameters etc. Every application server or servlet container offers a way to provide information via JNDI lookups to applications running inside of it.

So you could always use the same JNDI lookup key (e.g. "jdbc/yourDatabase") inside your application and configure the container/server to provide the correct information via this key. This way you don't have to modify the application itself but instead you use the application server facilities to configure which information should be provided via this lookup key. This should be enough for typical use cases I think. For example if you have an application server for testing you usually want to use a test database together with it. From your application's view this doesn't make any difference because the JNDI key would be the same. All that you or an administrator would have to do is to configure the application server to provide configuration parameters for the correct database etc.

Marco Ehrentreich wrote:
I hope this was more or less clear

But I'm sure there are other ways to configure a web application without having to modify the application itself. Even though Maven profiles would be a solution to easily build different WARs I'd still be interested to hear about other ideas.

Marco


Thanks a lot, Marco!

I have seen the JNDI solution! And i think is one of the best! But i develop in seam and i'm looking for something more integrated system. I.E. if I put my .property file in my deploy directory, how i have to modify my code to read the values and replace them in a correct configuration? Several libraries manage the initialization and the resorceBundle! Can i use it to solve my matters?

Have you some code that i can read? Also with the solution that you proposed me!

Thanks

Angelo Mario
 
 
subject: keeping properties file out of war
 
Similar Threads
Help with JBoss 3.2.3
write File to server with servlet
problem deploying a war
reading a properties file from the war file
Don't see properties files after deployment from Jdeveloper 11g