MacBook Pro M1, MacOS Ventura 13.1 -- but same problem over multiple MacOS versions.
Java version 17.0.1 -- but same problem using Java 8, 11, etc.
Double-click on a Jar in Finder and nothing happens. Have checked all the logs and cannot find any logged error.
Solved one problem - This is a fat-Jar which has flattened many other library Jars. Found that one of the libraries included signature files (in META-INF, SIGNINGC.RSA & SIGNINGC.SF).
This Jar would not start either by double-click or on the terminal: java -jar MyJar.jar
The latter gives a "Class not found" for the main class. Assume that Java examines the Jar, sees the signature files (from some library), takes the signature of the whole fat-Jar and once they do not match ignores the Jar. Since this is the only jar, then it cannot find the main class.
Note: It would be great if an error was printed indicating that "MyJar.jar failed verification and has been ignored" - would have saved a week of investigation!!!
This was solved by creating a script that unpacked the Jar, deleted the signature files, then re-packed the Jar. At least: java -jar MyJar.jar now works.
Unsolved Problem Even after the above fix, some Jars still will not launch from a double-click. Even worse, Jar will launch using JavaLauncher from command line.
Works -- java -jar MyJar.jar
Works -- /System/Library/CoreServices/JavaLauncher.app/Contents/MacOS/JavaLauncher MyJar.jar
Does not work -- double-click the Jar from Finder, or right-click, select Open With JavaLauncher.app
Update 2023-12-08 Have not had this problem for several months, have now upgraded to MacOS Sonoma 14.1.1 (but think that is irrelevant).
Now have a jar which launches OK twice with a double-click, but then fails.
Did manage to get a log from JavaLauncher on the failures - key info appears to be this:
Exception Type: EXC_CRASH (SIGKILL (Code Signature Invalid)) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: CODESIGNING 4 Launch Constraint Violation
BTW Jar has not been changed, and it did launch successfully twice. (Modified date has not changed either.) So why was JavaLauncher OK for two launches, and now fails.
Have the whole log - is there any way to attach it to this question?
SOLVED - WTF This was compiled for Java 8, actually executing on 21.0.1 - but do not think that matters.
Anyway, the application puts up a JDialog for a login to the application. JDialog has Yes and Cancel buttons. If you login, all proceeds normally. If you Cancel then the application exits with a System.exit(1) - and get a popup Java Application Launch Failed.
From that point on, cannot double-click to launch the app (but can launch it from the terminal).
All I can think of is that the System.exit(1) sets a flag somewhere that this Jar failed during launch, and therefore all future launch attempts are aborted.
If the System.exit(1) is changed to a System.exit(0), then can continue to double-click to launch.
Did check the extended attributes on the file, but nothing obvious.
Does anyone have a clue??? Seems extremely strange!