8

When I double click the jar file, the GUI program doesn't start by itself. Instead I have to open the Command prompt and then type java -jar abc.jar and only then it starts up. Why is that? What do I need to do to avoid this?

Is it that I have some problem with the default jar file opener? What should be the jar file opener?

Laurel
  • 5,965
  • 14
  • 31
  • 57
program-o-steve
  • 2,630
  • 15
  • 48
  • 67

9 Answers9

2

Maybe you would like to follow the instructions in this post: Running JAR file on Windows.

Just a minor note though. The exact syntax for me to work was in my Windows XP: C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe -jar "%1" %

Community
  • 1
  • 1
user1485864
  • 499
  • 6
  • 18
2

if nothing happens, then don't you get any error message like could not find main class or something similar?

I would suggest check your jar file association. On command-line type:

ftype | find "jarfile"

Sometimes, even resetting it works, find out the absolute path of JRE and run the command:

ftype jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*  

This would most probably solve your problem.

Johnydep
  • 6,027
  • 20
  • 57
  • 74
  • OK, we have the file associations are in place through Control Panel. I type this on my machne, but the other developer does not. Mine works, his doesn't. How do you correct this? Thanks – Andez Jun 22 '12 at 09:06
  • This worked for me. Changing the file type associations through the control panel didn't work. I had to type this command into the command prompt, but instead of the "jre7" part of the above command, I replaced it with the JRE version I had installed on my system. I think the problem happened because I also have more than one version of the JDK installed on my system, and the JDK binaries don't like running jar files for some reason, even though they're totally capable of doing it. After installing a JDK, the "jarfile" association probably got changed to the JDK binaries instead of the JREs. – Eric Townsend Jul 12 '20 at 09:07
1

If your jar file opens successfully from the cmd line means its a correct jar and everything is in place. Now you have to associate the correct program with it.

Right click on the jar -> Open With -> Go to JRE/BIN/javaw.exe -> OK

Now all the jar files are associated with the correct program. Try now!

Anuja
  • 409
  • 6
  • 18
1

I had this same problem. In my case, I think it was because I was using Scanner(system.in) input. By default, Windows opens .jar files with javaw.exe (thanks Johnydep), the version of java that runs without a terminal. In my case, running javaw -jar myJar.jar didn't work either.

I ended up writing a tiny batch file that uses the regular java.exe: java -jar myJar.jar

jonkb
  • 11
  • 1
0

Navigate to:
File->export->Java->Jar file->Next->use the tree to select the files you want to be included in your jar->Next->Next->
now i guess comes the part you have missed
at the bottom under "Main Class" click "Browse"->selcet the class you want to run when double click->press ok->finish.

should work now.

I couldn't find this answer anywhere and it solved my problem after i had same issue.

Amitk
  • 153
  • 2
  • 10
0

I had the same problem in Linux with a jar generated by Intellij, and I find that it's the problem of permission, the jar file's permission is "-rw-rw-r--", you need to add the permission of execute:
$chmod +x xx.jar, and double click.

SHI Yuxin
  • 1
  • 1
0

Which operating system? You need to configure your default applications. In KDE this is under System Settings -> Default Applications. For Gnome, Mac, or Windows you will have to google to find where to set it.

dotancohen
  • 30,064
  • 36
  • 138
  • 197
0

On windows: right click on jar -> open with -> choose programm... -> select "Java (TM) Platform SE binary".

Optionally, check the "Always use the selected programm to open this kind of file".

steffinchen
  • 497
  • 4
  • 12
-3

Maybe it is because your jar is not an executable jar due to which you cannot execute it directly by double clicking on it.

  • 2
    If that were the case, it would fail from the command line using the -jar option. Not a down-voter, but you might consider editing or deleting this post to avoid more down-votes. – Andrew Thompson Feb 13 '12 at 12:06