我有一个名为helloworld.jar的JAR文件。 为了运行它,我在命令行窗口中执行以下命令:
java -jar helloworld.jar
这工作得很好,但我如何执行它与双击? 我需要安装什么软件吗?
我有一个名为helloworld.jar的JAR文件。 为了运行它,我在命令行窗口中执行以下命令:
java -jar helloworld.jar
这工作得很好,但我如何执行它与双击? 我需要安装什么软件吗?
当前回答
如果你需要分发你的.jar文件,让它可以在其他人的Windows电脑上运行, 你可以在命令提示符中创建一个简单的.bat文件:
java -jar MyJavaTool.jar
并将.bat文件放在与.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上找到
如果使用eclipse生成java文件,可以选择将其导出为可运行的jar文件。我用我的程序做了这个,我只要点击罐子,它就会像这样运行。这将工作在两个windows,以及os x。
创建.bat文件:
start javaw -jar %*
然后选择app default,用这个。bat文件打开。jar。
当启动.jar文件时,它将关闭cmd。
编译:
javac -cp ".;./mysql-connector-java-5.0.8.jar;mybatis-3.0.1.jar;ibatis-2.3.0.677.jar" MainStart.java
为运行:
java -cp ".;./mysql-connector-java-5.0.8.jar;mybatis-3.0.1.jar;ibatis-2.3.0.677.jar" MainStart
在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上测试