aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Properties File from Jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Properties File from Jar" Watch "Properties File from Jar" New topic
Author

Properties File from Jar

Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
I am reading all the strings for my assignment from a Properties file and also am storing the user selected preferences from this file.

Now in case the current working directory does not contain the suncertify.properties file then i have to create a new one with the defaults read from the jar file. Please can someone help me solve this?
How do i read from the file that is present in my currently executing jar. Or should i hard code the string values in an interface?


-Sam Codean<br />SCJP 1.4 (98%)<br />SCJD 5.0 (87.5%)
Mike Ngo
Ranch Hand

Joined: Oct 16, 2006
Posts: 89
I am reading all the strings for my assignment from a Properties file and also am storing the user selected preferences from this file.


"all the strings for my assignment" means the strings for your application?
If that is the case, follow the common convention and put them in a bundle.

The default user settings should be part of the class that read/write properties file.
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
Yes all the strings for my application.
please can you elaborate on what you just said?
I have two sets of data, all the strings of the ui
and the preferences of the user. I store all of it in the suncertify.properties file. I do use a ResourceBundle to read the Strings but my question still remains how do i read it? if the file is not present then i cannot use any strings and hence i have to go to default for sTrings. I have not hard coded any string in any of my classes but i hard code the default values of data file , port number, UI Strings etc in the code and if the props file is present then overwrite it?
Mike Ngo
Ranch Hand

Joined: Oct 16, 2006
Posts: 89
You can store the application strings in a resource file. The resource file is jar'ed along with the application classes in the runme.jar so the application can always find it.

|_ ApplicationResources.properties
|_ suncertify.db



The application can be run from any dir so if the suncertify.properties file cannot be found you can use the applicatin default. If it is present, you can overwrite the application default.
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
Thanks Mike. I was confused how will the application read from a file that is bundled in a jar. You made me life easy.
Thanks a ton
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Properties File from Jar
 
Similar Threads
Ant Query
Reading properits file from an ejb
finding properties outside jar files?
Reading external properties file from EJB
read properties file from jar