Results 1 to 11 of 11
  1. #1
    aianta is offline Member
    Join Date
    Apr 2011
    Posts
    66
    Rep Power
    0

    Default Executable JAR does not create files

    Hello folks,
    I was wondering what sort of steps are required to give an executable JAR write permissions. Or what else would cause an executable JAR to be unable to create files?

    Basically, I have an application that runs just fine in eclipse, and creates the appropriate files (with relative path eg:../save.txt ) using the file writer, buffered writer combo. When I export the application using eclipse and select "extract libraries to jar" from the options in the export wizard a JAR file is generated with no errors. When the JAR is run, either through command line or just by clicking it. The jar is incapable of creating the same files it was writing when run through eclipse.

    No exceptions are encountered in the console.

  2. #2
    Gotcha is offline Member
    Join Date
    Jun 2015
    Location
    America
    Posts
    29
    Rep Power
    0

    Default Re: Executable JAR does not create files

    Linux? I think you just need to run it with proper permissions.. Type su(enter) and enter your password.. Then launch the app again.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Executable JAR does not create files

    No exceptions are encountered in the console.
    Do all the catch blocks have calls to printStackTrace() to show exceptions?

    Could the files that are created be in another folder?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Executable JAR does not create files

    Quote Originally Posted by Gotcha View Post
    Linux? I think you just need to run it with proper permissions.. Type su(enter) and enter your password.. Then launch the app again.
    That could be dangerous (something might get overwritten or there could be a bug in the program). I would recommend putting in some print statements do show where you are trying to write the file. Make certain you record the absolute path name. Also print out any return values.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Executable JAR does not create files

    I always suffer from File I/O anxiety. What IF you totally screw up and overwrite important files. That anxiety does not go away no matter how well I test things.

    Hence I always build the file I/O super-defensively; the application defines a specific spot wherein file I/O is allowed to happen (say: a specific subfolder of the user folder) and if any attempt is made to do something with a file outside of that DMZ, it errors out.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    aianta is offline Member
    Join Date
    Apr 2011
    Posts
    66
    Rep Power
    0

    Default Re: Executable JAR does not create files

    Do all the catch blocks have calls to printStackTrace() to show exceptions?
    Yup, e.printStackTrace() is called on all catches of IOException.

    Linux? I think you just need to run it with proper permissions.. Type su(enter) and enter your password.. Then launch the app again.
    Windows, I attemped adding a java.policy file in the same folder from a template found on stack overflow but that didn't fix it.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Executable JAR does not create files

    You still need to print out the expected target directory and file name. A relative directory from Eclipse will probably be different than when you run it from a CLI.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    aianta is offline Member
    Join Date
    Apr 2011
    Posts
    66
    Rep Power
    0

    Default Re: Executable JAR does not create files

    You still need to print out the expected target directory and file name. A relative directory from Eclipse will probably be different than when you run it from a CLI.

    Regards,
    Jim
    Thanks, I found the problem. It seems that to create my file object I used "../" in the filepath. When the application was exported it was trying to create files in the relative filepath of the application + "../generatedFolder/" so you'd get something like: "c:/users/aianta/desktop/../generatedfolder" which was a no go. Removing the "../" form my file paths seems to have fixed the issue.

  9. #9
    Gotcha is offline Member
    Join Date
    Jun 2015
    Location
    America
    Posts
    29
    Rep Power
    0

    Default Re: Executable JAR does not create files

    Sorry ignore

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Executable JAR does not create files

    As you already noticed, the current working directory is probably not what you expected; you can find the current working directory in the system properties object with key "user.dir", but it is more convenient to use the property "user.home" and navigate from that directory; (also see the API docs for the System.getProperties() method).

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Executable JAR does not create files

    You can delete posts. It is frowned upon to delete or modify issues in posts that folks have responded too. But if you change your mind about something its find. Go to advanced editing and you should see how to do it. Once you delete your post, I will delete this one (helps clean up things a bit).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. create windows executable using executable jar file
    By sarwar1234 in forum New To Java
    Replies: 2
    Last Post: 02-07-2011, 08:29 PM
  2. Create Executable Jar file
    By sarwar1234 in forum New To Java
    Replies: 11
    Last Post: 10-28-2010, 12:26 PM
  3. Create Executable Jar file
    By sarwar1234 in forum New To Java
    Replies: 3
    Last Post: 09-27-2010, 05:10 PM
  4. About Executable JAR files
    By paluee in forum New To Java
    Replies: 4
    Last Post: 03-31-2009, 07:03 PM
  5. executable files
    By akinpam in forum Advanced Java
    Replies: 10
    Last Post: 01-06-2009, 04:01 AM

Posting Permissions

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