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。如果启动失败的话,将显示一个带有错误信息的对话框。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM