geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <>
Subject Re: How to read and write a bundle properties in a war?
Date Fri, 06 Jul 2007 01:02:06 GMT

On Jul 5, 2007, at 2:44 AM, appel wrote:

> appel wrote:
>> Hi,
>> I have inside my war file, which is extracted when deployed in  
>> Geronimo, a
>> properties file I want to both read, and also write. Reading the  
>> file is
>> easy with ResourceBundle, but I can't think of a way to modify the
>> properties file... for instance changing the value of some property.
>> I can open the file manually with a full path, but I don't want my  
>> web app
>> to be dependent on the system it's deployed, for instance if I  
>> have to
>> deploy it on another computer using Geronimo and it's located in  
>> another
>> directory.
> However, I don't want to override any changes to the properties  
> file if I
> redeploy the application, so I need to generate the properties file  
> the
> first time the application is run and keep it OUTSIDE the
> extracted-directory.
> That is...
> My Geronimo installation is located in "/opt/geronimo", and my  
> deployed web
> application is located in
> "/opt/geronimo/repository/stuff/SomeApp/0.1/SomeApp-0.1.war/"
> But, if I write a file (with no path) it will be written into
> "/opt/geronimo/bin/somefile". I want this "somefile" to be written  
> into
> "/opt/geronimo/repository/stuff/SomeApp/0.1/", but this path can  
> change
> depending on how I deploy it and where.
> Any ideas?

I'm glad you realized that writing files into your application may  
lead to problems :-)

Geronimo has a var directory for this purpose, I suggest you put your  
configuration file there.

You can find out where the var directory is by using the ServerInfo  

You should be able to get the system info gbean by declaring a gbean- 
ref in your geronimo plan and looking it up in jndi.  However this  
isn't tested a lot and I can't guarantee it will work.  I think it's  
only available in geronimo 1.2 and 2.0: it might be in 1.1.1 also.

The gbean ref should look something like


and you'd look it up something like:

ServerInfo serverInfo = (ServerInfo) new InitialContext().lookup 

File myConfig = serverInfo.resolveServer("var/myappconfig/");

Note I'm using resolveServer which will still work even if you've  
relocated the var directory, perhaps if you're running multiple  
servers off the same repository.

Hope this helps
david jencks

> -- 
> View this message in context: 
> write-a-bundle-properties-in-a-war--tf4028664s134.html#a11443595
> Sent from the Apache Geronimo - Users mailing list archive at  

View raw message