views:

301

answers:

4

I an wanting to create a Java application that is installed on multiple platforms (Windows,Mac OS, Linux) as a part of this install I wish to register a URL protocol handler, so that my app loads when links are clicked.

i.e. I want something like this: myprotocol://example.com

Is there any sort of consolidated way of doing this? Or some sort of framework that extrapolates the difference across the different OS's.

+1  A: 

I would recommend that you use Java Webstart rather than try to invent a new link scheme. It's already supported by any browser that has Sun Java installed.

kdgregory
I think Webstart wont cut it as the application will need to do things outside of Webstart security restrictions, I think installation is necessary.
Dan
By signing your application you can get full access.
Thorbjørn Ravn Andersen
As long as your user says "OK", a Webstart app is indistinguishable from any other.
kdgregory
Webstart wont do the trick as if Java is not installed the jnlp file is not recognised, which confuses laymen users. Plus I need the file\utl association.
Dan
A: 

In Firefox you can register your own protocol.

This article describes more about the protocol registration. Probably you could automate it from there.

OscarRyz
Thanks, but a ff extension would not be comprehensive enough.
Dan
Dan, then please state what would be comprehensive enough...
Thorbjørn Ravn Andersen
@Thorbjørn Not being reliant on Firefox being installed, need to assume the user could be using any of the main browsers - needs to be an installed application (I think).
Dan
@Dan: That's what the second article is all about. If you manage to automate that registration process then you're done. There's an alternative though, based not in protocol name, but in the file extension. I'll post the link in another answer.
OscarRyz
+1  A: 

As an alternative, using the JDIC project you can associate files with specific applications.

This may be useful for your proposes. But instead of registering the whole protocol ( which may be somehow complicated ) you may register the file type only.

So, a link like this:

 <a href="http://example.com/file.dan"&gt;Dan File</a>

May be opened with your application.

Here's the sample code to register your app to open that file type:

AssociationService serv = new AssociationService();
Association logassoc = new Association();

logassoc.addFileExtension("DAN"); 
logassoc.addAction( new Action("open", "C:\\WINDOWS\\JAVA.EXE -jar C:\\dan.jar %1"));

Here's the complete article: Understanding JDIC File-Type Associations

OscarRyz
A: 

You'll probably need to do this in a platform-specific fashion. Here's how to do it in OS X

http://www.cocoadev.com/index.pl?HowToRegisterURLHandler

Sam Barnum