executing .jar file with an argument by mouse right-click on Windows?

耗尽温柔 提交于 2019-12-01 06:33:58

Follow these steps:

  1. Open regedit (as administrator).

  2. Locate key HKEY_CLASSES_ROOT\*\shell. In case you want to add the context menu for a specific extension only, use e.g. HKEY_CLASSES_ROOT\.xml\shell for xml. If the shell key doesn't exist, create it (right-click on the parent key and select New -> Key).

  3. Right-click on the shell key, and select New -> Key. Enter the name of the command displayed in the context menu, e.g. Check Bug Report.

  4. Right-click on the Check Bug Report key and select New -> Key. Enter text command (in lowercase).

  5. Click on the command key and then double-click on the (Default) key in the right pane to edit the string value. Enter the command to be executed. Placeholder for the argument is %1. For ChkBugReport_ver.jar, you can use

    java -jar "C:\Path\To\ChkBugReport_ver.jar" "%1"
    

See also this tutorial.

(Works with my Windows 7)

BlueYorker

The best answer above didn't work for me, it just opened a new window asking me what I'd like to open it with. I found a command that works much better. Same as first answer above but slightly different command (#4): cmd /k java instead of java. It runs it in a cmd window and the file is created in the current directory of the bug report.

  1. Locate key HKEY_CLASSES_ROOT\*\shell (Create shell key if it doesn't exist)

  2. Right-click on the shell key, select New -> Key. Enter the name of the command you'd like to display in the context menu (ie. Check Bug Report).

  3. Right-click on the "Check Bug Report" key you just created and select New -> Key. Name it command.

  4. Click on the command key, double-click on the (Default) key in the right pane and enter the following command to be executed:
    cmd /k java -jar c:\PATH\Chkbugreport.jar "%1"

try add it to HKEY_CLASSES_ROOT*\shell

I use the following registry to add Notepad2 to the right-click content menu

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT*\shell\Notepad2] @="Notepad2"

[HKEY_CLASSES_ROOT*\shell\Notepad2\command] @="D:\Tools\Notepad2\Notepad2.exe %1"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!