0

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?

Samaranth
  • 385
  • 3
  • 16
  • Without seeing the code, all we can do is guess. My first guess is that it’s related to the current directory and the use of relative file names. My second guess is that file permissions are responsible. – VGR Apr 03 '20 at 18:28
  • @VGR In what regard do you consider code helpful / relative file names as the cause of the problem? The problem occurs for all runnable .jar files, no matter if self-written applications, a simple hello world or "famous" Java applications written by other programmers or companies (especially applications like the latter previously worked on my notebook when doubleclicking but now won't). My general understanding is that .jar files that run using CMD should also run when double clicking them. And what would be that guess considering file permissions? – Samaranth Apr 06 '20 at 07:10
  • If the code is using relative file names, whether those files are readable (and thus, whether the program encounters an IOException) will depend on the current directory. The current directory may be different when running with `java -jar` than it is when double-clicking. – VGR Apr 06 '20 at 16:11
  • Ok, I've been checking my code and in the server-class I create a file using an absolute path to store hashed login data: `File file = new File("C:/Util/authHashes.lvs");` whereas I use an absolute path in the client-class to put two SystemProperties. What is weird now is that I'm able to start the server by doubleclicking but not the client although they both only use absolute paths. I'll quickly add the corresponding parts of the code to the original post for more clarity. – Samaranth Apr 07 '20 at 07:24
  • I would temporarily surround the entire body of `main` (or the run/call method of each thread, if you have multiple threads) with a try/catch that creates a file in a known location, and calls [printStackTrace(PrintStream)](https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/Throwable.html#printStackTrace%28java.io.PrintStream%29) to save the exception to that file. – VGR Apr 07 '20 at 17:43

0 Answers0