Running JAR file on Windows

前端 未结 25 2021
故里飘歌
故里飘歌 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条回答
  • 2020-11-22 02:27

    First set path on cmd(command prompt):

    set path="C:\Program Files\Java\jre6\bin"
    

    then type

    java -jar yourProgramname.jar 
    
    0 讨论(0)
  • 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.
    0 讨论(0)
  • 2020-11-22 02:27

    I had the same problem in Windows 10. I fixed it using righ-click on the "helloworld.jar" and go to properties and click on change button under "Opens with:" and select "Look for another app on this PC". In the "Open with..." dialog box, go to your Java folder location on your PC and open corresponding jdk folder and then open the bin folder and select "javaw.exe" from there. Then next time your "helloworld.jar" will open the normal way.

    Usual java location example : "C:\Program Files (x86)\Java\jdk1.8.0_111\bin".

    0 讨论(0)
  • 2020-11-22 02:29

    I´m running Windows 7 x64 and was unable to use any of these fixes.

    This one worked for me afterall:

    http://thepanz.netsons.org/post/windows7-jar-file-association-broken-with-nokia-ovi

    There is an archive which you can download containing a .bat file to run, but check the path of the actual javaw.exe!!!!

    0 讨论(0)
  • 2020-11-22 02:31

    If you use eclipse for making your java files, you can choose to export it as a runnable jar file. I did this with my programs and I can just click on the jar and it will run just like that. This will work on both windows, as well as os x.

    0 讨论(0)
  • 2020-11-22 02:31

    use .bat file:

    Put your command in a .bat file. here, your command will be java -jar path\yourJarName.jar. Something like: java -jar C:\workspace\myApplication.jar

    Save it and double click on bat file to run your jar.

    0 讨论(0)
提交回复
热议问题