无法在双击时运行可执行的 .jar 文件。

huangapple 未分类评论52阅读模式
英文:

Runnable .jar file not executed when double clicking

问题

不久之前,我遇到了这个问题,当双击一个可运行的 .jar 文件时,它不会执行。今天,我想着研究一下解决这个问题,并阅读了一些关于这个主题的不同 Stack Overflow 文章。

首先,我必须说以下几点:

  • 这个问题出现在我公司的笔记本电脑上,运行着 Windows 8,以及我个人的 Windows 10 台式机上。
  • 我很确定大约在 1.5 到 2 年前,在笔记本电脑上双击是可以工作的。
  • 但是在台式机上,即使是在去年十月安装之后,双击仍然不起作用,我甚至可能已经尝试通过重新安装 JRE 来解决这个问题。
  • 与许多文章中描述的情况不同,我可以通过在命令提示符中调用 "java -jar application.jar" 来正常运行应用程序,但是双击以及尝试使用 "打开方式" 选择 Java SE 平台二进制文件都没有任何反应。

根据一些帖子的建议,我尝试运行了 Jarfix,然而现在的行为如下:
我为我的学士论文编写了一个客户端-服务器应用程序,这个应用程序工作得非常好,昨天我还通过命令行运行了这个应用程序。在使用了 Jarfix 之后,我现在可以通过双击来启动服务器,但是当双击客户端时什么都不会发生。我已经按照 这篇文章 中所描述的正确设置了文件类型关联,一切看起来都正确。

当然,我也尝试了不同的程序,而不仅仅是我的自己的应用程序。同样的问题也出现在其他程序上,例如(在我的 Windows 10 台式机上)尝试运行 Life in the Woods(对于不了解的人来说,这是一个相当流行的 Minecraft 模组包),而在之前的 Windows 10 台式机上,双击是可以正常运行的。

我对这个问题的困扰不在于我不能通过运行命令来绕过它,而是一方面总是需要在命令行中切换到所需的位置并运行这个命令,这实在很烦人;另一方面,在安装了 JRE 之后,这个问题绝对应该能够正常工作。对于大多数人来说,它能够正常工作,但对于一些少数人来说,会发生一些随机的问题 - 这些问题在更或多或少相同的条件下出现,这不是任何一种软件应该表现出来的方式。

如果有人能帮助我解决这个问题,或者指出我可能忽略或遗漏的任何事情,我会非常高兴。

编辑:

正如 @VGR 指出的那样,使用相对路径的文件操作可能是问题的原因,因此以下是在两种情况下使用文件操作的地方:

服务器端:

File file = new File("C:/Util/authHashes.lvs");

客户端:

systemProperties.put("javax.net.ssl.keyStore", "C:/Util/auth/labkey.jks");
systemProperties.put("javax.net.ssl.keyStorePassword", "password");
systemProperties.put("javax.net.ssl.trustStore", "C:/Util/auth/labtrust.jks");

奇怪的是,这两个类都使用绝对路径,但是当双击时服务器会启动,而客户端不会启动。如果两者都使用相同类型的路径,它们不应该完全相同吗?

英文:

For quite some time I have encountered this issue that when doubleclicking a runnable .jar file it won't execute. Today I thought I'd have a look into solving this issue and read a bit through various SO articles regarding this topic.

First of all I have to say the following:

  • The problem occurs on my company's notebook running WIN 8 as well as on
    my private WIN 10 desktop
  • I'm pretty sure about 1.5 - 2 years ago on the laptop doubleclicking worked
  • On the desktop however even directly after installation (which was in October last year) doubleclicking didn't work and it might be that I even already tried fixing the issue by reinstalling the JRE
  • As opposed to many situations described in various posts I can properly run the applications by calling "java -jar application.jar" in cmd but doubleclicking AS WELL AS trying to "open with" Java SE platform binary results in nothing happening

As suggested by several posts I tried running Jarfix however now the behaviour is as follows:
I had written a client-server application for my bachelor thesis which worked perfectly fine, I actually ran the application yesterday through cmd. After using Jarfix I'm now able to start the server by doubleclicking whereas the client side won't do anything when doubleclicked. I already checked for the correct filetype association as described in this post and everything looks correct.

Also I of course checked this with different programs as well and not only with my own applications. The same issue also appears for example (on my WIN 10 desktop) when trying to run Life in the Woods (for those not knowing it, it's a quite popular Minecraft mod pack) whereas it worked perfectly fine on my previous WIN 10 desktop when doubleclicking.

The problem that I have with this issue is not that I'd not be able to bypass it by running cmd commands but on the one hand it's simply annoying to always cd to the desired location and run this command and on the other hand it's simply something that has to definitely work after installing a JRE. It doesn't make any sense that for most people it works and for some few people random stuff happens - all more or less under the same conditions, that's not how any kind of software should behave.

I'd be really happy if anyone could help me solving this or point me towards anything I might have overlooked and forgot to check.

EDIT:

As pointed out by @VGR file operations using relative paths might be the reason for the problem hence below the two cases where file operations are being used:

Server-side:

File file = new File("C:/Util/authHashes.lvs");

Client-side:

systemProperties.put("javax.net.ssl.keyStore", "C:/Util/auth/labkey.jks");
systemProperties.put("javax.net.ssl.keyStorePassword", "password");
systemProperties.put("javax.net.ssl.trustStore", "C:/Util/auth/labtrust.jks");

What is weird is that both classes use absolute paths but the server starts when doubleclicking while the client does not. If both use the same kind of path shouldn't they both behave exactly the same?

huangapple
  • 本文由 发表于 2020年4月3日 19:26:13
  • 转载请务必保留本文链接:https://java.coder-hub.com/61010817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定