6 Replies Latest reply: Dec 28, 2013 3:31 PM by TPD-Opitz-Consulting-com RSS

If property files that used to “configure the application” can be  stored in the jar file ?

mrsAngelo Newbie
Currently Being Moderated

Hi,

I already used properties file without problems for localizing information.

In that case the property file was stored as a resource in a package; and I used the Class ResourceBundle to manage the operations and the ClassLoader to access to the file.


Actually I need to use property files “To save the configuration of the application”.
In this case I need also to update information stored inside the file.property, and I used the same procedure as before to manage it (ClassLoader to get data- also for writing).


I had problems in this case: that the data was never modified inside the properties file.

I investigate, and now I think that the problem comes from writing in the property file that is located in the .jar file.

For what I know, it is impossible to change resources putted in the .jar files.

 

 

I found a solution: to store the properties files out the jar files; and in this way all is good.

But it would be more comfortable to store inside.



My question is : if a file property used to “save the configuration of the application “ have to be put out of jar, or is there another way ??

 

thank you for a replay

Regards

 

Angelo

  • 1. Re: If property files that used to “configure the application” can be  stored in the jar file ?
    baftos Expert
    Currently Being Moderated

    >I found a solution: to store the properties files out the jar files; and in this way all is good.

    >But it would be more comfortable to store inside.


    Think about your jar as the equivalent of a Windows EXE. It contains your program. You have a new version of your program, you update the EXE or the jar.

    Would you feel comfortable to store the configuration inside an EXE and therefore lose it when you update? So you found the right solution.


    The fact that both your configuration and your resources use property files should not mislead you. Property files are just a storage format, a bit like XML. Where they are stored depends on their intended use.

  • 2. Re: If property files that used to “configure the application” can be  stored in the jar file ?
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated

    as @baftos wrote: any kind of configuration should be saved outside of your jar files.

     

    The best place for configuration files depends on he information contained and who should be able to change it.

    Eg.: some configurations are only useful for the actual user running your program (last window size, last item viewed, last folder a file was opened from ...). Those are best store in the user home like this: new File(System.getProperty("user.home"),".YourApplicationName/config.properties")

     

    Other configuration may reflect some general adjustments unique to the computer your program is running on (location of Java runtime or third party software to use...) Those configurations should be  stored in the installation path of you program. But this is rarely needed.

     

    bye

    TPD

  • 3. Re: If property files that used to “configure the application” can be  stored in the jar file ?
    mrsAngelo Newbie
    Currently Being Moderated

    thank you for your answers.

     

    I know that what you said is right ...

    This problem is new for me (I need to save, on the client applications, the name of the computer where the server database run, on a network) .

     

    I didn't make an installation for my little program, so I need always  to remember to put the config.property file together to the jar file.

     

    This is not comfortable and, because of this, I would like to know if exists a better arrangement  than that I use.

     

    Regards

     

    Angelo

  • 4. Re: If property files that used to “configure the application” can be  stored in the jar file ?
    darke Explorer
    Currently Being Moderated

    mrsAngelo wrote:

     

     

    I didn't make an installation for my little program, so I need always  to remember to put the config.property file together to the jar file.

     

    This is not comfortable and, because of this, I would like to know if exists a better arrangement  than that I use.

     

     

    Have your program try to find the config file  , If it cant alert the user and collect relevant information from the user to create a config file .

  • 5. Re: If property files that used to “configure the application” can be  stored in the jar file ?
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated

    > I didn't make an installation for my little program, so I need always  to remember to put the config.property file together to the jar file.

     

    So do this

    - The 'default' config file is in the jar.

    - The application looks for the 'current' config file on the file system.  If it does NOT find it then it extracts the 'default' from the jar and writes it to the the file system.  After that the application then can write and update the config file, on the file system, all it wants.

  • 6. Re: If property files that used to “configure the application” can be  stored in the jar file ?
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated

    jschellSomeoneStoleMyAlias wrote:

     

    > I didn't make an installation for my little program, so I need always  to remember to put the config.property file together to the jar file.

     

    So do this

    - The 'default' config file is in the jar.

    - The application looks for the 'current' config file on the file system.  If it does NOT find it then it extracts the 'default' from the jar and writes it to the the file system.  After that the application then can write and update the config file, on the file system, all it wants.

    And don't forget to add a time stamp to the config file that may tell you later that the config file is outdated and should be overwritten (or merged).

     

    bye

    TPD

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points