我有一个名为helloworld.jar的JAR文件。 为了运行它,我在命令行窗口中执行以下命令:
java -jar helloworld.jar
这工作得很好,但我如何执行它与双击? 我需要安装什么软件吗?
我有一个名为helloworld.jar的JAR文件。 为了运行它,我在命令行窗口中执行以下命令:
java -jar helloworld.jar
这工作得很好,但我如何执行它与双击? 我需要安装什么软件吗?
当前回答
最简单的方法可能是升级或重新安装Java运行时环境(JRE)。
或:
Open the Windows Explorer, from the Tools select 'Folder Options...' Click the File Types tab, scroll down and select JAR File type. Press the Advanced button. In the Edit File Type dialog box, select open in Actions box and click Edit... Press the Browse button and navigate to the location the Java interpreter javaw.exe. In the Application used to perform action field, needs to display something similar to C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe" -jar "%1" % (Note: the part starting with 'javaw' must be exactly like that; the other part of the path name can vary depending on which version of Java you're using) then press the OK buttons until all the dialogs are closed.
这是从这里偷来的:http://windowstipoftheday.blogspot.com/2005/10/setting-jar-file-association.html
其他回答
开始。球棒是唯一对我有用的东西。
打开一个文本文档并输入。Java -jar,不管你叫。jar
另存为start.bat,保存在与要执行的.jar文件相同的文件夹中。然后运行。蝙蝠
如果你需要分发你的.jar文件,让它可以在其他人的Windows电脑上运行, 你可以在命令提示符中创建一个简单的.bat文件:
java -jar MyJavaTool.jar
并将.bat文件放在与.jar文件相同的目录中。
另一种通过单击/双击运行jar文件的方法是在 文件的名字。例如,您可以将文件MyJar.jar重命名为-jar MyJar.jar。
当然,您必须拥有与java.exe相关联的.class文件。这可能不是在所有情况下都有效,但对我来说大多数时候都有效。
我在Windows 10上也遇到了同样的问题。我用右键单击“helloworld.jar”修复了它,然后进入属性,点击“打开:”下的更改按钮,然后选择“在这台PC上寻找另一个应用程序”。在“Open with…”对话框中,打开PC上的Java文件夹位置,打开相应的jdk文件夹,然后打开bin文件夹,选择“javaw.exe”。然后下次您的“helloworld.jar”将以正常方式打开。
通常的java位置示例:“C:\Program Files (x86)\ java \jdk1.8.0_111\bin”。
在regedit中打开HKEY_CLASSES_ROOT\Applications\java.exe\shell\open\命令
双击左边的default,在java.exe路径和“%1”参数之间添加-jar。