How to run Java programs by clicking on their icon on Windows?

后端 未结 12 2677
太阳男子
太阳男子 2020-12-01 22:52

I have written a Java program that uses Java swing library. Now I would like to execute this program by double clicking on the executable file on Windows just like any other

12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 23:14

    While the others mention excellent choices like creating a native executable, there is another useful method: creating a shortcut.

    • Right click your desktop, expand the "New" option, and click on "Shortcut".
    • Type "javaw.exe". Click next.
    • Name it whatever you want. Click done.
    • You'll notice the newly created shortcut on your desktop. Right click it and choose "Properties"
    • In the "Target" textfield, append "-jar path-to-your-jar.jar" where you replace "path-to-your-jar.jar" with the actual path to your jar
    • You can also now optionally change the icon to whatever icon you want

    This shortcut can be pinned to the taskbar and be used from anywhere (considering you provided an absolute path to your JAR).

提交回复
热议问题