简体   繁体   English

爪哇视窗。 为什么我可以在命令提示符下运行 jar 文件但不能双击它

[英]Java Windows. why can I run a jar file on command prompt but not double clicking it

Now on this machine earlier just typing in the command prompt: java现在在这台机器上早些时候只需输入命令提示符:java

resulted in the command prompt saying java wasn't recognized.导致命令提示符说无法识别 java。 now the machine does have java installed , so I just added the java home and javahome/bin to path.现在机器确实安装了 java,所以我只是将 java home 和 javahome/bin 添加到路径中。 and now pressing java causes java to be recognized but by double clicking a jar file, but I am not getting the software to run.现在按 java 会导致 java 被识别,但是通过双击 jar 文件,但我没有让软件运行。 But when I go to command prompt and type in the prompt "java -jar nameofJar.jar" the application runs fine.但是当我进入命令提示符并输入提示符“java -jar nameofJar.jar”时,应用程序运行良好。 Not sure what is the issue.不知道是什么问题。 I added the environment variables to make sure it targets the jar file.我添加了环境变量以确保它针对 jar 文件。 I do notice something its not seeing the jar file as a "Executable jar file" simple a "jar file".我确实注意到一些事情,它没有将 jar 文件视为“可执行 jar 文件”,而只是“jar 文件”。

You have to tell java to execute your file with javaw.exe as told by @Carcigenicate您必须按照@Carcigenicate 的指示告诉 java 使用javaw.exe执行您的文件

  1. Start "Control Panel"启动“控制面板”
  2. Click "Default Programs"点击“默认程序”
  3. Click "Associate a file type or protocol with a specific program"单击“将文件类型或协议与特定程序相关联”
  4. Double click .jar双击.jar
  5. Browse C:\\Program Files\\Java\\jre7\\bin\\javaw.exe浏览 C:\\Program Files\\Java\\jre7\\bin\\javaw.exe
  6. Click the button Open点击按钮打开
  7. Click the button OK点击按钮确定

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

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