java可以从cmd运行jar但不能通过双击运行jar [英] java can run jar from cmd but not by double clicking

查看:118
本文介绍了java可以从cmd运行jar但不能通过双击运行jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用jdk7创建了一个jar文件。我试过运行它,但一直出错。事实证明它指的是jre6而不是jdk7中的jre。所以,我使用以下命令来改变它

I just created a jar file using jdk7. I tried running it but kept getting an error. It turned out it was pointing at a jre6 and not the jre in jdk7. So, I used the following command to change it

ftype jarfile =C:\ path to jre\bin\javaw.exe-jar%1 %*

ftype jarfile = "C:\path to jre\bin\javaw.exe" -jar "%1" %*

之后,我试图再次双击我的jar文件,但它弹出一个窗口,要求我选择一个程序来打开它。当我选择与上面相同的javaw.exe文件时,它会运行但会立即退出而不执行任何操作。我可以通过执行java -jar file.jar命令在cmd中运行它。我甚至尝试删除.jar注册表项,但这让我回到了让我选择要打开的程序的地步。如果重要的话,我正在运行Windows 7终极版。

After that, I tried to double click on my jar file again, but it popped up a window asking me to choose a program to open it with. When I chose the same javaw.exe file as above it runs but exits immediately without doing anything. I can run it fine in cmd by doing the java -jar file.jar command. I even tried deleting the .jar registry key, but that just got me back to the point where it asked me to choose a program to open with. I'm running windows 7 ultimate if that matters.

编辑:
在注册表中有3个子键:OpenWithList,OpenWithProgids和UserChoice。我已将所有默认值更改为上面的路径,但UserChoice除外,它不允许我从regedit编辑它。当我删除它并尝试运行jar文件时,它会打开选​​择一个程序再次打开窗口。由于某种原因,它忽略了其他注册表项

In the registry there are 3 subkeys: OpenWithList, OpenWithProgids, and UserChoice. I've changed all the defaults to the path above except UserChoice which won't let me edit it from regedit. When I delete that and try to run the jar file, it opens up the choose a program to open with window again. For some reason it ignores the other registry keys

推荐答案

我不确定为什么没有一个解决方案有效,但我重新安装了jre7,它现在​​有效。

I'm not sure exactly why none of the solutions worked, but I reinstalled jre7 and it works now.

这篇关于java可以从cmd运行jar但不能通过双击运行jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆