我有一个名为helloworld.jar的JAR文件。 为了运行它,我在命令行窗口中执行以下命令:
java -jar helloworld.jar
这工作得很好,但我如何执行它与双击? 我需要安装什么软件吗?
我有一个名为helloworld.jar的JAR文件。 为了运行它,我在命令行窗口中执行以下命令:
java -jar helloworld.jar
这工作得很好,但我如何执行它与双击? 我需要安装什么软件吗?
当前回答
如果你有一个名为Example.jar的jar文件,请遵循以下规则:
打开notepad.exe 编写:java -jar示例 保存扩展名为。bat 将其复制到包含.jar文件的目录 双击它以运行.jar文件
其他回答
在Windows XP *中,你只需要2个shell命令:
C:\>ftype myjarfile="C:\JRE1.6\bin\javaw.exe" -jar "%1" %*
C:\>assoc .jar=myjarfile
显然使用正确的JRE路径和任何你想要的名称,而不是myjarfile。
检查当前设置:
C:\>assoc .jar
C:\>ftype jarfile
这次使用第一个命令返回的值(如果有的话),而不是jarfile。
*未在Windows 7上测试
不幸的是,这并不容易,因为微软在最近的Windows版本中删除了高级文件关联对话框。-对于较新的Windows版本,您可以只指定将用于打开.jar文件的应用程序。
修复在Windows上打开.jar文件需要两个步骤。
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. 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" %*
注:
不要在那里使用java.exe,因为它会打开shell窗口。 本线程中提到的jarfix工具很可能只是为您修改注册表。我更喜欢手动注册表更改方法,因为这意味着系统管理员可以将注册表更改“推送”到网络中的所有工作站。
如果你有一个名为Example.jar的jar文件,请遵循以下规则:
打开notepad.exe 编写:java -jar示例 保存扩展名为。bat 将其复制到包含.jar文件的目录 双击它以运行.jar文件
在regedit中打开HKEY_CLASSES_ROOT\Applications\java.exe\shell\open\命令
双击左边的default,在java.exe路径和“%1”参数之间添加-jar。
如果使用eclipse生成java文件,可以选择将其导出为可运行的jar文件。我用我的程序做了这个,我只要点击罐子,它就会像这样运行。这将工作在两个windows,以及os x。