I would like my java application to automatically launch and display a .txt file when a user selects anything with that file type (The same behavior Microsoft word has when you select a .docx file)
I have followed the jpackage documentation here: https://docs.oracle.com/en/java/javase/14/jpackage/support-application-features.html#GUID-8D9F0607-91F4-4070-8823-02FCAB12238D
to setup file associations with my java application. I used this properties file to specify my application should open when a user selects a .txt file:
FAtext.properties:
mime-type=text/txt
extension=txt
description=Text source
This works. After installation my application starts when a user selects a .txt file.
However, my application doesn't actually open the .txt file because I am unsure how to provide the file name/location to my application.
I believe the solution is specifying another type of launcher with new args. For example:
OpenTxtFile.properties:
arguments=openTextFile locationOfTextFile
but how can I actually pass the locationOfTextFile argument to the launcher?
To setup file associations your
jpackage
command needs to contain--file-associations FAtext.properties
. Note that mime type is wrong above - should betext/plain
After installing the new MSI file you can check the associations in new CMD.EXE:
See if the part after "=" is mentioned by
ftype
:This should print something like:
Note that Windows may already have Default Apps set up for "txt" so your app may not be launched unless you visit Settings > Apps > Default Apps then "Choose default applications by file type".
If your application gets launched after double click on txt file you should be passed the TXT file as first parameter. JavaFX start() will print params with and you'll need to use :