Eamonn
Eamonn

Reputation: 617

How to enable a Java application to open files directly. e.g. right-click on a file or directory and being able to click on "open with mytool"

I have a general question regarding Java applications and their interaction with the overall OS (Windows, Linux and Mac).

If I have a directory with a certain set of files pertinent to a particular application, is it possible to add a context item to the OS menu which will allow the user to open up those files directly using my Java application?

I have been trying to find answers to this but didn't come across anything relevant.

Thanks!

Upvotes: 2

Views: 361

Answers (2)

Allan
Allan

Reputation: 2939

Edit:

Install4j is a commercial product that I use to create cross platform installers for my Java application. It has the ability to do file associations for different OS.


Assuming Windows....

This question is not java specific. To do this in Windows you need to modify the registry.

A good way to do this is with an installer tool such as NSIS

In you install script, you can modify the registry: See Ref

Finally see this article on what registry keys to edit to get this functionality: http://www.howtogeek.com/howto/windows-vista/add-any-application-to-the-desktop-right-click-menu-in-vista/

These keys might changes between different version of windows.

Upvotes: 0

Andrew Thompson
Andrew Thompson

Reputation: 168845

Use Java Web Start to deploy the application. It provides many nice features including registering an interest in a file-type (in the JNLP launch file). There is a demo. of this in the JNLP file API example, where the app. registers an interest in ..

..file extension .zzz (simply a file type unlikely to clash with existing file associations) of content type text/sleepytime.

Try the sand-boxed version, which actually prompts the user as to whether or not to make the file association. In a trusted app., it will simply go ahead & attempt to make it.

You can also control file type assocations in the program using the IntegrationService (I've had no time to experiment with the service, so there is no demo. yet).

Making a file association using JWS should work on Windows, *nix & OS X.

Upvotes: 1

Related Questions