Java 无法执行 .jar 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21363051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to execute .jar file
提问by Martin D
I'm having a problem with running .jar files. Here's what I've observed:
我在运行 .jar 文件时遇到问题。这是我观察到的:
- running executable .jar by doubleclicking doesn't do anything, not even start a process
- running it from cmd by typing
javaw myfile.jar
doesn't do anything as well, I've redirected STDERR but it doesn't say anything - because of school requirements I'm developing in BlueJ, when I run my code directly from this IDE, it works and starts processes like
java.exe
orjavaw.exe
- when I try to compile my console program from cmd and then run it by
java myclass
, it works
- 通过双击运行可执行文件 .jar 不执行任何操作,甚至不启动进程
- 通过键入从 cmd 运行它
javaw myfile.jar
也没有做任何事情,我已经重定向了 STDERR 但它什么也没说 - 由于我在 BlueJ 中开发的学校要求,当我直接从这个 IDE 运行我的代码时,它可以工作并启动类似
java.exe
或javaw.exe
- 当我尝试从 cmd 编译我的控制台程序然后运行它时
java myclass
,它可以工作
I'm working on Windows 7 Professional with Java SE 7u51 JDK installed. I've already tried to uninstall anything that had "java" in its name and then install only JDK or only JRE. I've also tried to run jarfix or manually delete all .jar associations in registry. I've added my JRE path to other system variables. Nothing has worked for me.
我正在使用安装了 Java SE 7u51 JDK 的 Windows 7 Professional。我已经尝试卸载名称中包含“java”的任何内容,然后仅安装 JDK 或仅安装 JRE。我还尝试运行 jarfix 或手动删除注册表中的所有 .jar 关联。我已将我的 JRE 路径添加到其他系统变量中。没有什么对我有用。
Please do you have any idea what to try next? Thank you.
请问您知道接下来要尝试什么吗?谢谢你。
Resolved:
Thanks to the answers I've managed to resolve the problem with doubleclicking as well. I've just had to:
已解决:
多亏了这些答案,我也设法通过双击解决了这个问题。我只好:
采纳答案by Ankur Shanbhag
Couple of quick solutions:
几个快速解决方案:
Use
java -jar <jar-file-name>
Note: This will be useful if your jar is Runnable
Use
java -cp <jar-file-name> main-class-name
Note: Specify the entry point with the class-name to start execution.
用
java -jar <jar-file-name>
注意:如果您的 jar 是可运行的,这将很有用
用
java -cp <jar-file-name> main-class-name
注意:使用类名指定入口点以开始执行。