0

I have developed a media application with JavaFX that can browse through Windows Explorer when requested by the user and open files compatible with this application. Example: I can click on the "open files" button, browse through folders and open inside my application any files with the compatible extensions.

My question is: Can I click on a file in Windows Explorer and make that file open instantly with my application instead of any other application? Example: When you double click on a video file it opens with the default media player. What I want to achieve is that this file opens instead with my application.

Matheus
  • 11
  • 1
  • 3
  • 2
    https://docs.oracle.com/javase/tutorial/deployment/selfContainedApps/fileassociation.html – NineBerry Mar 05 '17 at 01:28
  • You have to go to a file you want to open. Right click it and select opens with and choose another app. You may have to also choose use another app on this pc. Find your program exe and click it. – SedJ601 Mar 05 '17 at 04:15
  • Is there any other way besides Java Web Start? It seems it's too much for what I'm trying to accomplish. – Matheus Mar 05 '17 at 06:27

1 Answers1

0

As you are developing JavaFX-applications, you might want to look at the javapackager, which is included with the Oracle JDK. But instead of using that javapackager directly, you might want to check out the javafx-maven-plugin, which contains a built-in support for having your own files being assigned to your application when being installed:

<plugin>
    <groupId>com.zenjava</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>8.8.3</version>
    <configuration>
        <mainClass>com.zenjava.test.Main</mainClass>
        <verbose>true</verbose>
        <fileAssociations>
            <fileAssociation>
                <description>association 1</description>
                <extensions>ext1</extensions>
                <contentType>application/dummy</contentType>
                <icon>somePathToIcon</icon>
            </fileAssociation>
            <fileAssociation>
                <description>association 2</description>
                <extensions>ext2</extensions>
                <contentType>application/dummy2</contentType>
            </fileAssociation>
        </fileAssociations>
    </configuration>
</plugin>

In order to have this working, just call mvn clean jfx:native and installers are created where that file-association is created for you.

You can find the example for single filetype-associations here: https://github.com/javafx-maven-plugin/javafx-maven-plugin/tree/master/src/it/22-create-fileassociations-single-mimetypes

For multiple file-extensions, you can find the example here: https://github.com/javafx-maven-plugin/javafx-maven-plugin/tree/master/src/it/21-create-fileassociations

Please keep in mind, that the file-fileassociations only is done while installing your application and will be removed on removal of your application, which means that developing you want to install it once and might want to replace that bundle.

Disclaimer: I'm the maintainer of the javafx-maven-plugin

FibreFoX
  • 2,858
  • 1
  • 19
  • 41