我有一个名为helloworld.jar的JAR文件。 为了运行它,我在命令行窗口中执行以下命令:

java -jar helloworld.jar

这工作得很好,但我如何执行它与双击? 我需要安装什么软件吗?


当前回答

如果需要通过双击jar文件来运行该jar文件,则必须将其创建为“Runnable jar”。你可以简单地用你的IDE来做。

如果您正在使用eclipse,请遵循以下步骤:

    To create a new runnable JAR file in the workbench:

1.From the menu bar's File menu, select Export.
2.Expand the Java node and select Runnable JAR file. Click Next.
3.In the  Opens the Runnable JAR export wizard Runnable JAR File Specification page, select a 'Java Application' launch configuration to use to create a runnable JAR.
4.In the Export destination field, either type or click Browse to select a location for the JAR file.
5.Select an appropriate library handling strategy.
Optionally, you can also create an ANT script to quickly regenerate a previously created runnable JAR file.

更多信息可以在Eclipse帮助页:LINK上找到

其他回答

我正在运行Windows 7 x64,无法使用任何这些修复程序。

这条对我来说还是有用的:

http://thepanz.netsons.org/post/windows7-jar-file-association-broken-with-nokia-ovi

你可以下载一个包含要运行的.bat文件的存档文件,但请检查实际的javaw.exe!!!!的路径

开始。球棒是唯一对我有用的东西。

打开一个文本文档并输入。Java -jar,不管你叫。jar

另存为start.bat,保存在与要执行的.jar文件相同的文件夹中。然后运行。蝙蝠

首先在cmd(命令提示符)上设置路径:

set path="C:\Program Files\Java\jre6\bin"

然后输入

java -jar yourProgramname.jar 

在regedit中打开HKEY_CLASSES_ROOT\Applications\java.exe\shell\open\命令

双击左边的default,在java.exe路径和“%1”参数之间添加-jar。

除了所有其他的建议,还有一件事你需要考虑。你的helloworld.jar是一个控制台程序吗?如果是,那么我不相信您能够将其变成一个可双击的jar文件。控制台程序使用常规的cmd.exe shell窗口作为它们的输入和输出。通常jar“启动器”绑定到javaw.exe,它不会创建命令shell窗口。