Results 1 to 15 of 15
  1. #1
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Thumbs down Error when double-clicking a jar file

    Alright, so I had Eclipse generate a jar file for my mini-game, but when I double click it, it returns
    Java Code:
    Could not find main class: Main. Program will exit.
    On the other hand, when I run it from the command line, it runs perfectly fine. There is a Manifest file with the correct main class put in it, so that's ruled out as a possibility.

    Any Ideas?

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

    Default Re: Error when double-clicking a jar file

    There is a Manifest file with the correct main class put in it, so that's ruled out as a possibility.
    If the jar's manifest correctly identifies a jar entry as the entry point to your program then it's the error message that's ruled out as a possibility.

  3. #3
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Error when double-clicking a jar file

    To clarify, I used
    Java Code:
    java -jar Game.jar
    and it runs perfectly, but double-clicking doesn't

  4. #4
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Error when double-clicking a jar file

    Okay, while going through the Similar threads, I got that I needed to do
    Java Code:
    "C:\Program Files\Java\jdk1.6.0\bin\javaw.exe" -jar "%1" %*
    in the command prompt, but after trying that, it tells me "Error: unable to access jarfile %1"

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

    Default Re: Error when double-clicking a jar file

    Where did you see the error message when you double clicked the jar file?

    And, yes, what is the contents of its manifest and the location and contents of the class it specifies as the entry point?

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

    Default Re: Error when double-clicking a jar file

    What you posted in #4 doesn't look like what you'd type at the command prompt (and I'm confused: I thought you said it was already running fine from the command line.)

    Rather it looks like an action you would associate jar files with in WindowsExplorer. On XP you get at these from "Tools->Folder Options->File Types".

  7. #7
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Error when double-clicking a jar file

    Yeah, it runs fine from the cmd, that was just one of the answers in the similar threads.
    The message when I double clicked the jar file popped up in a Java Virtual Machine Launcher thing.
    The contents of the Manifest are
    Java Code:
    Manifest-Version: 1.0
    Class-Path: .
    Main-Class: Main
    And the entry point is Main.class

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

    Default Re: Error when double-clicking a jar file

    The message when I double clicked the jar file popped up in a Java Virtual Machine Launcher thing.
    That's strange. I don't get any launcher on this machine (XP/JRE7). The default behaviour if it can't find or load the main class is basically to do nothing.

    Did you change the action associated with opening jar files as suggested in #4. That's the default for Windows. (Of course you have to set the correct path to javaw.exe for however you have installed.)

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Error when double-clicking a jar file

    You have determined that the jar file contents are ok by being able to execute it from the command prompt with the command :
    java -jar Game.jar
    as posted in post#4.

    So the problem must be with what the OS is using as a commandline when you double click on the jar file.

  10. #10
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Error when double-clicking a jar file

    Quote Originally Posted by Norm View Post
    You have determined that the jar file contents are ok by being able to execute it from the command prompt with the command :
    java -jar Game.jar
    as posted in post#4.

    So the problem must be with what the OS is using as a commandline when you double click on the jar file.
    How do I change that?

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Error when double-clicking a jar file

    What version of Windows are you using? The change is easier on XP (see post #6) than on Windows7 where you will have to use the regedit program.

  12. #12
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Error when double-clicking a jar file

    Windows 7

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default Re: Error when double-clicking a jar file

    I've used the regedit program to fix the commandline associated with a file extension. It allows you to edit and change the registry. If you mess up the registry, you can hurt the OS.
    Ask Google about how to use regedit and see what tutorials are available.

  14. #14
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Error when double-clicking a jar file

    Alright, Thanks

  15. #15
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: Error when double-clicking a jar file

    There are various third party tools for fixing file associations in Win7. This one's free: Types

    Disclaimer: I haven't tested any of said tools nor researched reviews.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Double-clicking .jar files?
    By StokedOnMe in forum New To Java
    Replies: 11
    Last Post: 04-23-2014, 12:52 PM
  2. Replies: 4
    Last Post: 08-30-2011, 05:57 AM
  3. Double Clicking Executable Jar File
    By javawriter in forum New To Java
    Replies: 7
    Last Post: 07-30-2010, 10:26 PM
  4. Double clicking executables jar files?
    By cruxblack in forum New To Java
    Replies: 6
    Last Post: 04-23-2009, 02:00 AM
  5. Executing JAR File by double clicking
    By jasmu in forum Advanced Java
    Replies: 11
    Last Post: 04-22-2009, 12: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
  •