This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Properties File sharing across Mulipe Web applications Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "Properties File sharing across Mulipe Web applications" Watch "Properties File sharing across Mulipe Web applications" New topic
Author

Properties File sharing across Mulipe Web applications

Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
I have four different web applications running in my tomcat 6 server. I have some resource details like URL of each applications stored in the properties file to be used for the menu. There are other details as well

The problem is these details are duplicated across applications and while testing or deployment, each URL need to be updated in all the properties file.

Is there any way to make this properties file as common so that all the applications can access the same file.


SCJP 1.5, SCWCD 1.4.
Hanging between Web Services and EJB
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16103
    
  21

If I understand you correctly, you have a common properties file for multiple webapps.

The easiest way to do this - especially if you want to be able to use an alternate properties file for testing - is to place the properties file in an external location outside of the webapps and configure each webapp to use that file. For example, "/etc/mywebapps.properties" if you're on a unix/linux server.

You can make this location programmable by setting up a resource-reference in web.xml and setting the location (filename path) as a Context resource definition in each webapp's Context. You would then be able to retrieve the pathname of the resource file using JNDI (for example, "java:comp/env/webapp-properties", then open and load the properties using normal Java file I/O and System.properties calls.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
Yes your understanding is correct.

But our applications can be deployed in different locations under different OS.

So again this becomes a burden for the client who will decide where to deploy.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16103
    
  21

Ramkumar Subburaj wrote:Yes your understanding is correct.

But our applications can be deployed in different locations under different OS.

So again this becomes a burden for the client who will decide where to deploy.



That's an even more compelling reason to go that route. JNDI is OS-independent and you can set the location of the properties file path from the Tomcat admin webapp if editing Context files is an issue.

addendum: I spent several years in an environment where our development machines were Windows but the test and production servers were Solaris and later Linux. So I do have experience in this technique.
 
GeeCON Prague 2014
 
subject: Properties File sharing across Mulipe Web applications