I have an executable jar file which uses the SingleFrameApplication class. I am using netbeans 6.1 as my IDE.
In my code I have a reference to a properties file which is located in the src folder inside some package. When I run the application from netbeans, it runs fine but when i double click on the jar file though the application runs fine but when i try to access the properties file an exception is thrown..
The jar file is in the following path C:\Documents and Settings\15760\My Documents\NetBeansProjects\UTS\dist
Since user.dir is a system property which gives the current system directory i m in the above directory and there is no path saying src\\uts\\config\\envConfig.properties so i m unable to reach the file.
How do i fix this problem? My basic intention is to run the project with the help of jar file in some other machine which does not have an IDE or anything..
Following are the lines of code which i m using to access the properties file..
Thanks and Regards,
The link is not of much help because the problem is not in my code. When i run the code from the ide itself everything runs fine. The problem is while executing the jar i need the path that i have specified in the above code to be inside the same directory of the jar.
I m getting file not found exception.
As i said my objective is to run the jar file in some other machine.
Thanks and Regards,
System.getProperty("user.dir") returns the path from which the application was launched. That doesn't have to be the path where the JAR file is located. Therefore, it perhaps is a better idea to choose a different folder; something based on System.getProperty("user.home") perhaps. The user's home folder rarely changes, but it does mean that each user has its own version of the file. You can combine both the system and user specific files using cascading Properties objects: you put the system properties in a resource inside the JAR file which you then load into one Properties object. You then create a second Properties object with the first Properties object as its defaults. The second Properties object will then return the first Properties object's values if it doesn't have the properties itself. In code (ignoring closing of streams and null checks for clarity):