Bind custom file extension using java application in windows

I would like to “associate” several file extensions with my java application under windows. When the user double-clicks the file with the “associated” extension, I would like to open my application, and I need to find out the path to the file in which the application was run.

+5
source share
2 answers

If you are deploying an application. using Java Web Start , interest in type files can be declared in the startup file. See Demo . file services that ..

.. prompts the user to associate the .zzz file .zzz (just a file type that is unlikely to encounter existing file associations) of the text/sleepytime content type ...

When the user double-clicks the .zzz file, it should open in the application. In fact, the word "prompts" is not the whole story. If you run the sandboxed version, you will be prompted to associate the file type. Trusted version not verified.

To add user control to this process, look at the IntegrationService , which was introduced in 1.6.0_18 (I do not know if you have a demo of this yet). You can run it at startup after checking with the user.

+3
source

this should be done during installation. How do you plan to let your user install your application?

you must understand at this point that you just made things a lot more difficult. registering file extensions means tampering with the registry. What happens if the user no longer wants your application? or moves a file running your application?

You will need to select the creator of the installation. here's the question: https://stackoverflow.com/questions/3767/what-is-the-best-choice-for-building-windows-installers

and then you will have to learn this installer creator language. here, as what you ask is done in nsis. remember that the script takes care of issues such as "if the user uninstalls my application and I did not change file associations during installation, should I remove these file associations when uninstalling?" so it's a little longer. here it is anyway: http://nsis.sourceforge.net/File_Association

perhaps this can be done in a simpler way in another installer creator.

however, in this example, you provide the nsis registration function for the start command for your application, and then add% 1 to it in the Windows file association start command. so you have to give it a start command

 javaw -cp installpath\yourcode.jar package.name.MainClassName 

and then everything should work out. this, of course, will require some experimentation, and you will need to be sure how to start the application from the command line.

Good luck

+2
source

All Articles