Results 1 to 8 of 8
  1. #1
    javawriter is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default Double Clicking Executable Jar File

    Hi,

    I used eclipse to export a project as an executable jar file. The output jar file was able to be executed by double clicking the .jar icon. I tried to make an executable jar without the help of eclipse (using the command prompt)and I ran into an issue where I can run my program from my jar file using the command prompt (java -jar <jar file>) but I cannot run my program by double clicking the .jar icon (which I could do when I used eclipse).

    Does anyone know how I can make my .jar file execute by double clicking it? I know I can use a .bat file to make my program executable but my main goal is to try and reproduce the same behaviour as the eclipse executable jar file (for learning purposes).

    Thanks in advance.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    Opening and executing a file is an OS thing. What OS are you on?
    The java installation on Windows associates a command line with the .jar file to execute it when it is double clicked. The association is in the registry.

    You can also create a shortcut to the jar file and manually change the command that the shortcut executes by right clicking on the shortcut and selecting properties. The command line is in the Target field.

    I cannot run my program
    Do you get any error messages?

  3. #3
    javawriter is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    When I double click the jar file, nothing happens. No error messages show, and the program does not execute. I am working in windows XP.
    Last edited by javawriter; 07-30-2010 at 07:49 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    To execute via a double click the jar file must contain a manifest file with a Main-Class: entry. Open the jar file with WinZip or rename it to zip for windows to open it and check its manifest file. Copy and paste its contents here would help.
    If that is Ok, open a command prompt window, change to the folder with the jar file and enter:
    java -jar YOURJARFILENAMEHERE.jar

    Copy the command prompt screen and paste the messages to the forum.

  5. #5
    javawriter is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    My manifest file is very simple:

    Manifest-Version: 1.0
    Main-Class: comicbooks.Main

    The contents of my jar file are:

    META-INF/
    META-INF/MANIFEST.MF
    comicbooks/
    comicbooks/Main.class
    comicbooks/Comic.class

    The output from the command prompt is as follows (i wrote a very simple program that displays the condition and price of a comic book) :

    directory> java -jar comic.jar
    Title: The incredible Hulk
    Price: $30.00
    Condition: Mint
    directory>

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    That makes it look like its an OS thing. The double click on the jar file is not executing the correct command line.
    The command line is put in the registry and associated with jar files when Java is installed.

    Do the following to see what's associated with jar files on your system:
    Open Windows Explorer
    Click on Tools menu
    Click on Folder Options
    Select File Types tab
    Scroll down in the "Registered file types:" list until you see an entry for JAR.
    Select the JAR entry.
    Click the Advanced button
    In the Edit File Type window scroll down the list of Actions until you see the one in bold.
    Select the bold one
    Click the Edit button
    Select, Copy and paste here what is in the "Application used to perform action:" window.

    Be careful not to change anything and Cancel your way out of the open windows.

  7. #7
    javawriter is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    "C:\Program Files\Java\jre6\bin\javaw.exe" -jar "%1" %*

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    Is that the correct path to the javaw.exe file?
    My entry. I've modified it but has a command line that works.
    D:\Java\jre6_10\bin\javaw.exe -Xmx256M -jar "%1"
    Try copying that command line and pasting it into a command prompt window and replace everything after the -jar <space> with comic.jar and see what happens.
    Then do it again but change the command from javaw to java.

    Don't know what to suggest now.
    The jar file executes if you manually enter: java -jar comic.jar
    That would mean the manifest and class files in the jar are ok.
    Don't know why the command line you show from the registry doesn't work.

Similar Threads

  1. Double-clicking .jar files?
    By StokedOnMe in forum New To Java
    Replies: 11
    Last Post: 04-23-2014, 01:52 PM
  2. Executable File.
    By BeeGee in forum Advanced Java
    Replies: 13
    Last Post: 05-25-2010, 01:35 PM
  3. Exporting to a executable JAR file
    By Drun in forum Eclipse
    Replies: 4
    Last Post: 03-27-2010, 04:16 PM
  4. Double clicking executables jar files?
    By cruxblack in forum New To Java
    Replies: 6
    Last Post: 04-23-2009, 03:00 AM
  5. Executing JAR File by double clicking
    By jasmu in forum Advanced Java
    Replies: 11
    Last Post: 04-22-2009, 01:51 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
  •