问题
I have a self contained JavaFX application. For an improved user experience, I would like the user to click on a button/link on the browser and start the application. Just like magnet URI for torrent, the link contains metadata that is required to start up the application.
Is there a way to generate the executable for JavaFX application to associate with custom URI just like magnet URIs associated with torrent applications.
回答1:
Here is how to associate custom URIs with an application.
I already have a task that generates the native bundles.
First step is to enable verbose in your ant task so you can locate the build path.
As mentioned here, in 6.3.3 enable verbose and look for <AppName>.iss
file in the build directory, which is usuablly AppData/Local/Temp/fxbundler*
.
Make sure you have the directory that contains package directory in the classpath. Here is an example of how you can add that to the classpath:
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant" classpath="${build.src.dir}:${JAVA_HOME}/lib/ant-javafx.jar"/>
In my example I have package/windows with Drop-In Resources in src directory.
If you have file association, you will see something like this:
[Registry]
Root: HKCR; Subkey: ".txt"; ValueType: string; ValueName: ""; ValueData: "AppNameFile"; Flags: uninsdeletevalue
Just after this line you can add lines to add custom URI's registry entries.
If you don't have file association then you will add entries after
ArchitecturesInstallIn64BitMode=ARCHITECTURE_BIT_MODE
You can find the template of how AppName.iss file is generated at this location:
C:\Program Files (x86)\Java\jdk1.8.0_60\lib\ant-javafx.jar\com\oracle\tools\packager\windows\template.iss
Here you will find how to write lines like the one above
Here you can find what registry keys and entries that needs to be added for custom URI association.
来源:https://stackoverflow.com/questions/32505471/associate-custom-uri-schemes-with-java-self-contained-application-for-windows