Results 1 to 3 of 3
- 03-15-2009, 11:55 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
Program working fine on netbeans but not when run with jar file
Hello,
i have a java desktop application (Data viewer) which reads 2 .csv files and show their data into text areas. When i run the program through netbeans it works just fine but when i try to run it from the jar file it runs but cannot find the files. This is the relevant code for one of the files (the other one is the same): (the files are located in a folder called data inside the project folder)
String defaultPersonLocation =
System.getProperty("user.dir") + "\\data\\option18Person.csv";
String remainderPath = defaultPersonLocation.replace(System.getProperty(" user.home"), "").toString();
personFilename = System.getProperty("user.home") + remainderPath;
try {
personFile = new File(personFilename);
BufferedReader reader = new BufferedReader(new FileReader(personFile));
personData = reader.readLine();
while (personData != null) {
personArrayList.add(new Person(personData));
personData = reader.readLine();
}
reader.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
I managed to partly solve the problem by moving the files into the src folder
and change the following lines:
System.getProperty("user.dir") + "\\data\\option18Person.csv";
String remainderPath = defaultPersonLocation.replace(System.getProperty(" user.home"), "").toString();
personFilename = System.getProperty("user.home") + remainderPath;
To :
personFilename = "/option18Person.csv"
And now it works with the jar file as well as long as i have it in the same hard disk where i created it. For example if i move the whole project folder to another computer then the jar file will not read the files again. I need to fix that so the jar file could work in any computer.
- 03-16-2009, 02:22 PM #2
Can you check that the string that ends up in personFilename is what you're expecting? I don't think that the string operations shown will result in a valid path.
- 03-16-2009, 07:52 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
My program is not working
By MICHAELABICK in forum New To JavaReplies: 6Last Post: 12-22-2008, 11:05 PM -
netbeans+swing = painting program?
By yuriythebest in forum New To JavaReplies: 3Last Post: 12-14-2008, 08:55 PM -
Program Runs in NetBEans but Not in cmd
By MeathUltra in forum NetBeansReplies: 1Last Post: 12-09-2008, 05:38 AM -
application is not running please fine the solution for it.
By jagadeeshchinni in forum New To JavaReplies: 4Last Post: 09-28-2008, 10:14 AM -
Errors driving me crazy! although compiles fine
By irishsea2828 in forum New To JavaReplies: 1Last Post: 04-08-2008, 03:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks