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

查看:23
本文介绍了java可以从cmd运行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 jreinjavaw.exe" -jar "%1" %*

ftype jarfile = "C:path to jreinjavaw.exe" -jar "%1" %*

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

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,但不能通过双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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