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
lomidienAsked:
Who is Participating?
 
limaidealCommented:
We normally do this:

1. specify a common system place. such as /home/etc/myappconfig/config.xml to store customized ccnfig file.
2. When app start, it first go to the place to check if there's a config file or not. If so, ues it.
3. If no config file was found, use deault values. You can put your default values in another file in you jar file. So you dont need to modify your jar file anymore.
0
 
CEHJCommented:
Practicably you can't
0
 
CEHJCommented:
For this you should use user.home directory
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
CEHJCommented:
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
0
 
lomidienAuthor Commented:
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
0
 
CEHJCommented:
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
0
 
CEHJCommented:
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.

 
0
 
objectsCommented:
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.
0
 
aozarovCommented:
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.
0
 
CEHJCommented:
>> Write a little app that collects the values needed ...

Why? There's already an app that does that. It's called Ant ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.