简体   繁体   English

Java程序无法双击运行

[英]Java program won't run on double click

What the title says really. 标题真正说的是什么。 I've tried exporting it to a Runnable Jar File, checked the Manifest.MF, and tried running it with Java multiple times but with no luck. 我尝试将其导出到Runnable Jar文件,检查了Manifest.MF,并尝试使用Java多次运行但没有运气。 However, it does work when I navigate to the file using the command prompt and launch is using java -jar Name.jar. 但是,当我使用命令提示符导航到文件并使用java -jar Name.jar启动时,它确实起作用。 This shows it works but I just can't get it to launch by double clicking. 这表明它可以正常工作,但我无法双击启动它。

I guess you're trying to launch a commandline-app. 我猜您正在尝试启动命令行应用程序。 This kind of application can be launched by double-clicking aswell. 也可以通过双击启动此类应用程序。 There's only one problem: Java doesn't create a commandline-window by default and instead uses the commandline of the parent-process of the JVM, which in case of double-clicking doesn't own a console-window. 仅有一个问题:Java默认情况下不创建命令行窗口,而是使用JVM父进程的命令行,在双击的情况下,它不拥有控制台窗口。 In other words: the output to the console gets lost somewhere in the depths of your OS and the JVM and the program hangs as soon as any input is expected. 换句话说:控制台的输出在OS和JVM的某个深度丢失,并且只要有任何输入,程序就会挂起。

(Assuming your on Windows OS), if you right-click on it, do you see the option 'Open with' and then 'Java (TM) Platform SE binary', or something like that? (假设您使用的是Windows操作系统),如果右键单击它,会看到选项“打开方式”,然后是“ Java(TM)Platform SE二进制文件”或类似的选项? And if you opt to open with that, does it execute? 如果您选择打开它,它会执行吗?

If so, then you've probably set .jar files to open with a different application by default. 如果是这样,则默认情况下,您可能已将.jar文件设置为使用其他应用程序打开。 For example, I have my computer set up to open .jar files with jd gui as the default application. 例如,我将计算机设置为使用jd gui作为默认应用程序打开.jar文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM