在Windows上通过鼠标右键执行带参数的.jar文件?

5
我觉得ChkBugReport非常有趣: http://developer.sonymobile.com/knowledge-base/tools/analyse-your-bugreports-with-our-open-source-tool/ 我想在Windows7上以简单的方式使用它。
为了使用jar中的工具,我需要在命令提示符中输入以下内容:
java -jar ChkBugReport_ver.jar dumplog.txt
其中dumplog.txt是我要用该工具分析的记录。
问题在于,每次想使用它时都运行cmd并键入“java -jar ...blah blah..”相当繁琐,因此我希望将其链接到Windows资源管理器中鼠标右键上下文菜单中。
例如,浏览到我想在Windows资源管理器中分析的文件,然后右键单击该文件将提供菜单,如“运行ChkBugReport ..”,然后执行“java -jar ChkBugReport_ver.jar clicked-file.txt”并生成输出。
有办法做到这一点吗?
3个回答

6

请按照以下步骤进行操作:

  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"
    

请参考这个教程(也适用于Windows 7)。


我已经检查过了,但我想用一个额外的参数来运行它 - 选定的文件,这样它就会执行"java -jar ChkBugReport_ver.jar selected_file"。 - g3han
它不起作用 - 只有在 Windows 资源管理器左侧树中选择文件夹时,菜单才会出现..而不是文件。 - g3han
java -jar "D:\Path\To\MyJar.jar"。如果我在控制台中输入它,它可以正常工作。我想我应该提到我用的是Windows 8.1,但这不应该有影响,因为问题是运行特定的java -jar命令。 - H.v.M.
嗯,系统变量诸如PATH、JAVA_HOME等是否设置正确? - Mifeet
2
我尝试了这个,但Windows 10一直弹出“你想用什么打开它?”有什么解决办法吗? - Ryan
显示剩余6条评论

5
上面最佳答案对我没用,它只是打开一个新窗口询问我想用什么程序来打开。我找到了一条命令,它的效果要好得多。与上面第一个答案相同但命令略有不同(#4):cmd /k java而不是java。它在cmd窗口中运行,并在错误报告的当前目录中创建文件。
1. 找到 HKEY_CLASSES_ROOT\*\shell 键(如果不存在则创建 shell 键)。 2. 在 shell 键上右键单击,选择 New -> Key。输入您想在上下文菜单中显示的命令名称(例如:Check Bug Report)。 3. 右键单击您刚创建的 "Check Bug Report" 键,并选择 New -> Key。将其命名为 command。 4. 单击命令键,在右窗格中双击 (Default) 键并输入以下要执行的命令:
cmd /k java -jar c:\PATH\Chkbugreport.jar "%1"

2
这在我的Windows 10上运行正常...谢谢!顺便说一句:它确实保持了cmd窗口打开。 - Simon Baars
cmd /C java -jar c:\Path\myjar.jar "%1" - Hicsy
@SimonBaars:/C 是“关闭”开关,/K 是“保持打开”开关。 - Hicsy

0

尝试将其添加到HKEY_CLASSES_ROOT*\shell

我使用以下注册表将Notepad2添加到右键内容菜单

Windows Registry Editor Version 5.00

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接