Results 1 to 13 of 13
  1. #1
    vasilenko93 is offline Member
    Join Date
    Jan 2014
    Location
    Citrus Heights, CA
    Posts
    8
    Rep Power
    0

    Angry Program runs differently when executable jar.

    I have a little application that I made, it requires that I save data to a file in data/coins.cdp. When I run the application with java myProg in the terminal everything is correct, when I create the executable jar and run java -jar myJar.jar or ./myjar.jar everything also works. Even if I copy the jar to a different location, and run it through the terminal, it still works fine. Things get weird through when I copy the jar to a new location and double click on it, because then no folder gets created and no file is written.

    Why is that?

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Program runs differently when executable jar.

    Is your jar having the correct manifest file with main-class information in it? if you don't have it you can run a jar by double clicking it.

  3. #3
    vasilenko93 is offline Member
    Join Date
    Jan 2014
    Location
    Citrus Heights, CA
    Posts
    8
    Rep Power
    0

    Default Re: Program runs differently when executable jar.

    Here is my Manifest.txt file, I have no problem turning it on with double click, I have problems with Java not creating folders or writing files when I double click. Perhaps I need to change the working directory somewhere in the manifest file.
    Java Code:
    Manifest-Version: 1.0
    Created-By: Alex Vasilenko (codevs)
    Main-Class: counter/CoinCounter

  4. #4
    vasilenko93 is offline Member
    Join Date
    Jan 2014
    Location
    Citrus Heights, CA
    Posts
    8
    Rep Power
    0

    Default Re: Program runs differently when executable jar.

    My question is not how to make my program run, its why running it runs differently with double click. When I run my application through the command line it creates a folder and puts a file in it, then opens up the GUI. However when I double click on the jar it only opens up the GUI. Why is that.
    *EDIT* and yes, the manifest is in there.

  5. #5
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Program runs differently when executable jar.

    Have you try to check for exception that might happens during the folder creation process. There might be an error or exception occur, but you program is not handles the exception. Maybe simply log to a file the exception stack trace from your try-catch block if you have it in your code. For example what you don't have a write permission in the current directory? Should you get an permission denied error, but you don't see it because there was no message.

  6. #6
    vasilenko93 is offline Member
    Join Date
    Jan 2014
    Location
    Citrus Heights, CA
    Posts
    8
    Rep Power
    0

    Default Re: Program runs differently when executable jar.

    There are no permission problems, the jar is in my desktop. When I cd into my desktop with the command line and run it through the command line everything works correctly. But when I try to double click it on the desktop the file is not written, only the GUI loads up. And I do have System.out statements if an exception is thrown for creating the file, I have a feeling the files are being created somewhere else when I double click.

  7. #7
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Program runs differently when executable jar.

    Can you post the code related to creating the folder / file? Maybe we can see something in the code.

  8. #8
    vasilenko93 is offline Member
    Join Date
    Jan 2014
    Location
    Citrus Heights, CA
    Posts
    8
    Rep Power
    0

    Default Re: Program runs differently when executable jar.

    The entire code in found in this GitHub repository. I made it a year ago in eclipse, now I want to revive it without Eclipse and on Linux. The code can be found in source/counter/gui/FileWrite.java line 79.

  9. #9
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Program runs differently when executable jar.

    I've download your code from GitHub, compile it and build a jar. When I double click it it create a data directory with to file created coins.cdp and errorLog.err. I am running Windows 7 by the way.

  10. #10
    vasilenko93 is offline Member
    Join Date
    Jan 2014
    Location
    Citrus Heights, CA
    Posts
    8
    Rep Power
    0

    Default Re: Program runs differently when executable jar.

    Its what I feared, that its some Linux problem. Have you tried copying the jar to another folder, that is really where the problem is. Also thank you for helping.

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,869
    Rep Power
    5

    Default Re: Program runs differently when executable jar.

    Yes you're going to get very far in this business if you blame the tools. That's an escape route for managers, not for developers.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    vasilenko93 is offline Member
    Join Date
    Jan 2014
    Location
    Citrus Heights, CA
    Posts
    8
    Rep Power
    0

    Default Re: Program runs differently when executable jar.

    @gimbal2, you are right. Now that I am working on the application again I have some plans about a permanent location. So if the OS is windows it will go in My Documents, and if its Linux it will go in /home/$user/.CoinCounter/. I just though I have my Manifest file messed up or something.

  13. #13
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,869
    Rep Power
    5

    Default Re: Program runs differently when executable jar.

    Thank you, but

    Quote Originally Posted by vasilenko93 View Post
    I just though I have my Manifest file messed up or something.
    That would have been easy to research. If a wild guess would pop into my head, I'd start by researching what you can put in a manifest file to begin with and see if any of the options matches my situation. And then I'd quickly realize that guessing is not knowing and move along to treating the problem as something simple I'm missing again.

    That's the key to solving these kind of things: immediately kill the urge to think this is something mysterious, difficult or worst case scenario: weird. Its something simple, you're overlooking it, all you have to do is go figure it out. If you don't keep that frame of mind, the easy things tend to escape you and you're all the way up to spending hours building complicated workarounds before you stumble on that one tiny little thing and you feel really stupid. Speaking from experience there.

    I'm rambling here, feel free to just think "duh!" and move along ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 1
    Last Post: 01-23-2014, 06:36 PM
  2. Creating variables/arrays while the program runs
    By AGuyWhoSkis in forum New To Java
    Replies: 3
    Last Post: 05-31-2013, 04:40 AM
  3. playing music while program runs
    By liluma in forum New To Java
    Replies: 2
    Last Post: 05-04-2011, 05:16 PM
  4. Replies: 0
    Last Post: 10-04-2009, 02:47 PM
  5. Program Runs in NetBEans but Not in cmd
    By MeathUltra in forum NetBeans
    Replies: 1
    Last Post: 12-09-2008, 05:38 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
  •