David Jason wrote:I can also try another method - my jar should look for the properties file in folder in which it is kept.
SCJP, SCWCD.
|Asking Good Questions|
David Jason wrote:But, would this method be system dependent ? You know the "/" vs "\" of linux and windows respectively.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
David Jason wrote:But, would this method be system dependent ? You know the "/" vs "\" of linux and windows respectively.
I'm pretty sure that paths in Java can use '/', regardless of what OS it's running on.
However, as Amit said, accessing an external properties file is trickier. If it really must be an external link, then it might be best to make it a URL or URI, since then the program will (or should) be able to run even if it's on a remote system.
Winston
David Jason wrote:I want this properties file to stay outside the jar and my jar file should be able to locate this file on its own.
Paul Clapham wrote:
David Jason wrote:I want this properties file to stay outside the jar and my jar file should be able to locate this file on its own.
Why? It's much more convenient to put the properties file inside the jar. First of all that means you only have one file to distribute, rather than two. Secondly it means you don't have to figure out a way for the code to find where you installed the properties file.
David Jason wrote:What if someone wants to edit that properties file ? Lets say that the if the username and password for some account login changed. What happens after that ?
Paul Clapham wrote:
David Jason wrote:What if someone wants to edit that properties file ? Lets say that the if the username and password for some account login changed. What happens after that ?
Good question. Presumably it's the user of the application who wants to do that, and the application provides a way to do it.
It's also possible that you have to make occasional changes, perhaps like the password change which you described, but the changes are to be made by you and not by the user. In that case just generate a new version of the jar file, complete with the changed properties, and send it out to the user.
Paul Clapham wrote:In that case the application should write out the modified version of the properties file into the user's directory. (There's a system property which tells the application what the user's directory is.) And that means that to find the properties file, the application should first look in the user's directory, and then if it doesn't find the properties file there, it should look in the jar.
Paul Clapham wrote:Which is why I said:
Paul Clapham wrote:In that case the application should write out the modified version of the properties file into the user's directory. (There's a system property which tells the application what the user's directory is.) And that means that to find the properties file, the application should first look in the user's directory, and then if it doesn't find the properties file there, it should look in the jar.
David Jason wrote:I am not sure what you mean by "user's directory". I searched google for "java locate user directory".
Is this it - String userHome = System.getProperty("user.home"); ? Taken from here
David Jason wrote:
We assume that my code does not steal/misuse the login credentials in any way once it picks them up from the file.
SCJP, SCWCD.
|Asking Good Questions|
Consider Paul's rocket mass heater. |