Results 1 to 3 of 3
  1. #1
    nvlachos is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default 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.

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    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.

  3. #3
    nvlachos is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    It does print a valid string. Don't worry about it though, i solved it last night.
    Thank you for the reply

Similar Threads

  1. My program is not working
    By MICHAELABICK in forum New To Java
    Replies: 6
    Last Post: 12-23-2008, 12:05 AM
  2. netbeans+swing = painting program?
    By yuriythebest in forum New To Java
    Replies: 3
    Last Post: 12-14-2008, 09:55 PM
  3. Program Runs in NetBEans but Not in cmd
    By MeathUltra in forum NetBeans
    Replies: 1
    Last Post: 12-09-2008, 06:38 AM
  4. application is not running please fine the solution for it.
    By jagadeeshchinni in forum New To Java
    Replies: 4
    Last Post: 09-28-2008, 11:14 AM
  5. Errors driving me crazy! although compiles fine
    By irishsea2828 in forum New To Java
    Replies: 1
    Last Post: 04-08-2008, 04:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •