I have created a JavaFX application, deployed the .app file and it works fine. I then set the operative system to open all the files with a specific extension with my application. My problem is that when I double-click on a file, I get to open my application, but I do not know which file it opens.
I tried to check the application parameters with the function getParameters (). GetRaw ()
but it always gives an empty list.
Do anyone know how to get the path that opens the file?
I finally got a way to solve it.
I created a sample app to answer it by creating three sections:
Launcher MIP handler openfile
My app javafx The .application.Application is a class expanding class, the use of handler openfile is double-Kell event and finally the launcher is main.
Launcher.java: This class is important because the javafx.application extension that was defined within the main client. The application OpenFilesEvent won`t work properly (more precisely that OpenFilesEvent only Will be removed when the application was already opened). Public class launcher {public static zero main (string [] args) {if (System.getProperty ("os.name") includes ("OS X") {com. Apple.eawt.application a = com.apple.eawt.application.getApplication (); Handler openfile h_open = new handler openfile (); A.setOpenFileHandler (h_open); Application.launch (Main class, args); }}}
Handler OpenFile. Java: This class defines a fixed variable that stores the value of the file that opens the file. This is probably not the best solution, but this is the only way I can work for it now.
Public class Handler_OpenFile OpenFilesHandler {public static file file = null; @ Override public blank openfile (openfile event e) {file file: ef files ()) {this.file = file; }}}
MyApp.java: This class will be able to reach the fixed value specified in the Handler_OpenFile class and will retrieve the full path of the opening file.
Expanding the public class map app {@Override Public Zero Start (Stage Primary Stage) {Logger Logger = Logger. Tag ("log"); File Handler FH; Try {// Configure logger with this block handler and form FH = new file handler ("../logfile.log"); Logger.addHandler (FH); SimpleFormatter formatter = new SimpleFormatter (); Fh.setFormatter (formatter); // To logger.info any message the following statement is used ("Started with the app:" + Handler_OpenFile.file.getAbsolutePath ()); } Hold (security exception | IOException exception) {Exceptions. Print straps (); } {Try BorderPane Route = New BorderPane (); Visual View = New View (Route, 400,400); PrimaryStage.setScene (view); PrimaryStage.show (); } Hold (exception e) {e.printStackTrace (); }}}
Finally, in the build.xml file that makes your bundle, you must add the file association (in this example with files with .z extension):
& lt; Fx: info title = "sample" vendor = "me" & gt; & Lt; Fx: Collaboration Extension = "zzz" Details = "Sample Source" /> & Lt; / Fx: info & gt;
This will only work with the last update of Java (8u40). For the previous versions you have to manually change info.plist manually in your bundle as stated in it.
No comments:
Post a Comment