Running JAR file on Windows

前端 未结 25 2761
故里飘歌
故里飘歌 2020-11-22 01:57

I have a JAR file named helloworld.jar. In order to run it, I\'m executing the following command in a command-line window:



        
25条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 02:27

    Unfortunatelly, it is not so easy as Microsoft has removed advanced file association dialog in recent Windows editions. - With newer Windows versions you may only specify the application that is going to be used to open .jar file.

    Fixing .jar file opening on Windows requires two steps.

    1. Open the Control Panel, and chose "Default Programs -> Set Associations". Find .jar extension (Executable JAR file) there, and pick Java as default program to open this extension. It will probably be listed as "Java Platform(SE)". A faster alternative perhaps is straightforward right-click on a .jar file, and then change associated program by clicking on the "Change..." button.

    2. Now open the regedit, and open the HKEY_CLASSES_ROOT\jarfile\shell\open\command key. Luckilly for us, we may specify parameters there for the (Default) value. On my Windows system it looks like: C:\app\32\jre7\bin\javaw.exe" -jar "%1" %* but in most cases it is the following string: C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*

    NOTES:

    • Do not use java.exe there as it will open the shell window.
    • The jarfix tool mentioned in this thread most likely does nothing more than the registry modification for you. I prefer manual registry change method, as that implies that system administrator can "push" the registry change to all workstations in the network.

提交回复
热议问题