Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Configuration file settings

Posted on 2005-04-17
10
Medium Priority
?
203 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:lomidien
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13800522
Practicably you can't
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13800523
For this you should use user.home directory
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13800556
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lomidien
ID: 13801022
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 13801046
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
 
LVL 2

Accepted Solution

by:
limaideal earned 2000 total points
ID: 13801060
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 13801090
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
 
LVL 92

Expert Comment

by:objects
ID: 13802665
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
 
LVL 15

Expert Comment

by:aozarov
ID: 13803547
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 13804457
>> Write a little app that collects the values needed ...

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question