Launching a java application from an URI
I'm looking for a way to launch my java application when using a custom URI. Something in the lines of movie://superman/
This should start my application and display information about the movie "Superman".
if friends of my have my application installed as well, i can send them that URI so they can click on it.
I used to do this back in the days in VB6 but i lost my code and forgot how to do it.
OS: windows
Any help would be app开发者_StackOverflow社区reciated.
The actual mechanism to implement this is operating-system dependent (and thus not accessible from pure Java).
The general idea is to register your application as the protocol handler for the protocol in question.
On Windows you do that by writing the appropriate registry keys
..should start my application and display information about the movie "Superman".
If you can distribute your app. from a web site, you might take a slightly different approach:
- Launch the app. using Java Web Start.
- In the JWS launch file (JNLP format), add a custom file extension, e.g.
xuri
. - Send the user an
clickthis.xuri
file containing the URI of interest. - When the JWS app. registered to that file type is invoked, it will be passed
-open clickthis.xuri
as arguments to themain(String[])
. - Proceed from there..
This approach should work on any OS with 'modern' Java installed. JWS was available since 1.2, & became co-bundled with the JRE around 1.4.2.
精彩评论