Link to home
Start Free TrialLog in
Avatar of lomidien
lomidien

asked on

Configuration file settings

I have a configuration file that ships inside my .jar file.  I would like to be able to write information to this file as settings change so that there is not an additional file outside the jar.  How can I go about making changes to a simple text file residing inside the jar itself?

Thanks,
David
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Practicably you can't
For this you should use user.home directory
Doing so, btw, will ensure

a. that the data can be written
b. that the data are backed up properly if a rational backup strategy is in place
Avatar of lomidien
lomidien

ASKER

CEHJ,

Thaks for the answer.  It's not actually runtime settings that will change, but I deploy to varous client and each .jar has a configuration file inside to provide some details....now these never change once the app is deployed.  I won't do the deployments myself....someone else that is not a programmer will do those and I was looking for a way I could write, perhaps, an additional app to alter the file within the jar before it is deployed.  

Of course I could tell him to change the extension to .zip and recombine with the appropriate file that way, but I was shooting for something more elegant.

Thanks,
David
Depends on who's doing this. If it's

a. a customer - i'd proceed as per my suggestion
b. a programmer - you could use Ant to parameterize the correct config during build
ASKER CERTIFIED SOLUTION
Avatar of limaideal
limaideal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The command for 'b.' above would be something like (using a defalt target):

ant -Dclient.config=client-a.properties

...

ant -Dclient.config=client-b.properties

etc.

 
Write a little app that collects the values needed and uses them to create the necessary config file, and then jar up the class files and your created jar file.
Use the preference API to store/read client configuration.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/prefs/Preferences.html
Which wlll store them using OS-specific registries.
>> Write a little app that collects the values needed ...

Why? There's already an app that does that. It's called Ant ;-)