Fork me on GitHub

jar运行方法

直接用命令执行

导出时指定类,直接运行jar包会执行指定类的main方法

java -jar Xxx.jar 

运行其他类的main方法

java -classpath Xxx.jar com.xxx.classname

双击jar包运行方法

方案一

  在jar包同级,写个bat文件,如下

java -jar Xxx.jar     
pause

方案二

  右击jar文件 -》打开方式-》选择安装的jre/bin/javaw.exe。

  双击依然不行,因为双击相当于执行cmd命令 javaw Xxx.jar。

  修改注册表HKEY_CLASSES_ROOT\Applications\javaw.exe\shell\open\command,添加参数 -jar如下。

  补充:关于javaw的介绍,官网给出的是:

The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you do not want a command prompt window to appear. The javaw launcher will, however, display a dialog box with error information if a launch fails.

意思就是javaw和java是一样的,当不想要出现命令提示窗口时,用javaw。如果启动失败的话,将显示一个带有错误信息的对话框。

posted @ 2018-04-12 09:30  秋夜雨巷  阅读(8947)  评论(0编辑  收藏  举报