Results 1 to 11 of 11
  1. #1
    StokedOnMe is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

    Default Double-clicking .jar files?

    Hey guys, I've been programming for a while, but I never made executables... just ran it from the compiler. Now, however, I really want to have an icon for one of my programs that would be conveniently located and clickable. So, I made a jar file, both in Eclipse and BlueJ. When I run this file in command line, it works fine (with "java -jar ..."). In case of Eclipse, this worked with both "jar" and "Executable jar" options. However, when I double click the icon, nothing happens. First I was getting "can't find main class" error, but that was an easy fix with the manifest file. But now, nothing seems to happen at all. Could this be because the program is supposed to run in the command line or whatever the compiler offers and there is nothing to force the computer to open one of those windows? Please help, this is very frustrating )))

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    With Windows make sure you are using java.exe and not javaw.exe to run your jar file. The latter does not display a console window.

    Alternatively put the command that you know runs the program properly inside a batch file.

  3. #3
    StokedOnMe is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

    Default

    Ok, so I went to properties of the jar file and made it open with java.exe instead of javaw.exe. However, all that achieved is that now the DOS window flashes for a split second and disappears :/

    How would I put the command inside the file?

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    The following works for me (hw.jar just prints hello world to the console).

    Java Code:
    @echo OFF
    java -jar g:\hw.jar
    pause

  5. #5
    StokedOnMe is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

    Default

    Wow! Thanks a lot! That was easy ))) Didn't even need the "pause" line really... for the purposes of this program at least.
    Thanks again.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    You're welcome.

  7. #7
    Mekonom is offline Member
    Join Date
    Nov 2009
    Posts
    71
    Rep Power
    0

    Default

    A where mus I write this code?where is batch file in project?

  8. #8
    StokedOnMe is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

    Default

    You just create it in Notepad.

  9. #9
    nonaXOYO is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default

    I tried this and go an error:

    "Unable to access jar file g:\hw.jar"

    :confused:

  10. #10
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    hw.jar was an example jar file that was used to illustrate the batch file usage. (See #4 above). You will be unable to access it unless you have created it...

    If you have a problem it might be best to start your own thread and explain what that problem is. (what you are trying to achieve, what you have done, what happens when you do that.)

  11. #11
    yassin moulay is offline Member
    Join Date
    Mar 2014
    Posts
    1
    Rep Power
    0

    Default Re: Double-clicking .jar files?

    can i know where i will write this please and how to save it : save as (txt , bat, ....)
    please answer me please please please

Similar Threads

  1. Double clicking executables jar files?
    By cruxblack in forum New To Java
    Replies: 6
    Last Post: 04-23-2009, 02:00 AM
  2. Executing JAR File by double clicking
    By jasmu in forum Advanced Java
    Replies: 11
    Last Post: 04-22-2009, 12:51 PM
  3. Replies: 5
    Last Post: 03-21-2009, 09:32 PM
  4. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 08:39 AM
  5. Java3D: Clicking and getting coordinates?
    By seabhcan in forum Advanced Java
    Replies: 0
    Last Post: 01-11-2008, 02:46 PM

Tags for this Thread

Posting Permissions

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