1

This is a more specific version of the question I already asked on stackoverflow (How can I access a correct version of a Java Desktop class). I will reiterate here the problem, and clarify the question: I have a JavaFX application that can be used to edit files of a particular type on Windows OS. By using launch4j-maven-plugin I can make an exe file, and by using Inno Setup I can make an installer of this application that has a particular file type associated to it (kb files). If I install the application and double click on the file that this application is associated to while the application is not open already, the application opens and I can read the said file (I read main function args and use the filename to read the file). The problem I have is if the user tries to double click the file that this application is associated to, while the application is running. That does not work.

The question is: is there a way in Java 1.8 to respond to the event of double clicking the associated files for a JavaFX application ?

As already mentioned in the previous question, I tried using the Desktop class, but as I found out in the answer to that question, Desktop class has the methods to deal with this problem only starting from Java version 9. However, we cannot update Java to version 9 or higher, since that would require huge re-engineering effort on our side.

Z P
  • 11
  • 1
  • each click on a file should launch a new instance of the application. if you want to work with a single instance you simply send a message to the active instance of the application what to do. – mr mcwolf Dec 23 '22 at 10:22
  • here, perhaps, you have a problem with relying on a semaphore in `launch4j` to keep track of whether there is a running instance of the application. – mr mcwolf Dec 23 '22 at 10:24
  • Indeed, after removing the single instance element, the application now opens each file individually. It is not what we want in the long run, bur for now it will do the trick. – Z P Dec 23 '22 at 12:15
  • From here on, you should implement the function yourself. At first reading, you can use a `socket` to implement a semaphore for a started instance in java and at the same time use it for IPC between the two application instances (of course, the second one just sends the path to the file you want to open and finishes its work). – mr mcwolf Dec 23 '22 at 12:31
  • I understand, we can do that. Thanks! – Z P Dec 23 '22 at 12:37
  • See [JavaFX single instance app](https://stackoverflow.com/questions/41051127/javafx-single-instance-application/41052124#41052124), which implements mcwolf’s suggestion. – jewelsea Dec 24 '22 at 05:28

0 Answers0