This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am using Netbeans IDE for application development.
I am having a properties file for configuration which I am putting in the jar and accessing it via resourcebundle.
But what i want is put the properties file outside the jar and access it in the java class inside jar.
The jar file which i am using is the one from the dist folder of the project.
please help me with example how should i access the same?
Thanks for reply.
Yes my program is a stand alone application.
Giving path via command line argument will ask for the properties file path again and again as many times you run the application.
I want to put the properties along with jar file in same folder that is, I want abc.properties file and xyz.jar file in the same folder lmn.
xyz.jar will contain only Main.class file and nothing else other than Main.class and the files created by jar utility.
abc.properties file will be outside the jar file inside the same folder in which jar file is kept.
When abc.properties was inside the xyz.jar, Main class accessed it via ResourceBundle.getBundle("abc",Locale.getDefault())
How should I access the abc.properties file from outside the jar file using the Main.class ?
First, put your configuration file into the jar file and access it there -- you know how to do that.
Next, if you want to allow the user to modify or personalize the configuration, then store a copy of the configuration file in the user's home directory after the user makes changes to it. You can get the name of the user's home directory from the "user.home" system property.
Then to find the configuration for the user, first look in the user's home directory. If you find the file there, that's what you should use. If you don't, then you should use the default version which you deployed in the jar file.
(By the way: this doesn't seem to have anything to do with those certification exams. Let's move the thread to a regular Java forum.)