0

Here's the story:

I wrote a program yesterday and exported it to a jar file. I then tried to open it by double clicking it, and nothing happened. After a bit of research, I made sure that my jre was up to date (it is). I associated javaw.exe with jar files by right clicking the file and navigating to javaw.

The funny thing is that the file works in command prompt, meaning I can execute it there, but nothing happens on a double click on the desktop. So I thought it might be, because the program doesn't have a GUI or anything, meaning it has no pop up window. It's just text. So I wrote a tiny program that uses JOptionPane to display "Hello." That .jar also works if opened through the command prompt, but still doesn't open on a double click.

Does anyone know why?

If it helps, here's the second program code, which, as I mentioned, also doesn't work on a double click:

import javax.swing.*;

public class Hello {

    public static void main(String[] args) {

        JOptionPane.showMessageDialog(null, "Hello.");
    }

}
zyzz
  • 85
  • 2
  • 11

1 Answers1

2

The reason why it doesn't work is that you need to use -jar argument to start a .jar file with javaw. See here: http://www.wikihow.com/Run-a-.Jar-Java-File

When you simply associate file extension .jar with javaw.exe, the -jar argument is missing. As far as I know it is not easy to let it use -jar, because this option is not present in Windows GUI, but it can be done with some smart Windows registry editing tool. Read this question for more information: https://superuser.com/questions/136133/how-do-i-set-advanced-file-associations-in-windows-7

update: Create a helper .bat file contining javaw.exe -jar "%1" %* and associate .jar extension with this bat file.

Community
  • 1
  • 1
Al Kepp
  • 5,831
  • 2
  • 28
  • 48
  • Thanks for your answer! I'll read through the links for sure. Does that means that it's nothing wrong with the file, but more with how my system is handling it? – zyzz Oct 21 '14 at 01:18
  • If it can be started from the command line, the jar file is fine. – Al Kepp Oct 21 '14 at 23:22