How can a JavaFX application correctly handle opening of associated files on Windows in Java 1.8 - javafx

This is a more specific version of the question I already asked on stackoverflow (How can I access a correct version of a Java Desktop class).
I will reiterate here the problem, and clarify the question:
I have a JavaFX application that can be used to edit files of a particular type on Windows OS. By using launch4j-maven-plugin I can make an exe file, and by using Inno Setup I can make an installer of this application that has a particular file type associated to it (kb files). If I install the application and double click on the file that this application is associated to while the application is not open already, the application opens and I can read the said file (I read main function args and use the filename to read the file). The problem I have is if the user tries to double click the file that this application is associated to, while the application is running. That does not work.
The question is: is there a way in Java 1.8 to respond to the event of double clicking the associated files for a JavaFX application ?
As already mentioned in the previous question, I tried using the Desktop class, but as I found out in the answer to that question, Desktop class has the methods to deal with this problem only starting from Java version 9.
However, we cannot update Java to version 9 or higher, since that would require huge re-engineering effort on our side.

Related

System.IO.File.Open within netstandard2.0 library from xamarin.forms within UWP fileaccess UnauthorizedAccessException

I currently have a handler within my global Xamarin.Forms Mobile App project. This handler contains a System.Io.File.Open on a text file that is located within the Users Document directory.
However, when running the UWP application, it throws the following:
Exception thrown: 'System.UnauthorizedAccessException' in System.IO.FileSystem.dll
System.UnauthorizedAccessException: Access to the path 'C:\Users' is denied.
I do not have much experience with both Xamarin.Forms and UWP so possibly I am doing something wrong from the start. I did do some research before posting this question, and understood that UWP runs in a sandbox that requires user permission to access directories and/or files within specific locations.
I've heard however that setting the following within Package.appxmanifest would allow access to all directories the current user has access to:
<rescap:Capability Name="broadFileSystemAccess" />
However that didn't make any difference for me. Then I proceeded and allowed through Windows Settings the application to access the file system as mentioned somewhere. This didn't solve anything either.
Did some more research that UWP has it's own IO interface using IStorageHandlers and related. But these cannot be used within a netstandard2.0 library as far as I've seen.
How would one handle file operations from within a netstandard2.0 library that is included within a UWP application?
The broadFilesystemAccess capability will give an application access to all user-accessible files, but only via two mechanisms:
Windows.Storage APIs; or
CreateFileFromApp and similar Win32 APIs.
Since .NET doesn't use either of those APIs under the covers, it can't access locations outside of the app's package / data folders.
Not sure if there is another answer that would suit UWP applications, if there is, please do put them here. However, impatient me that wants to move on decided to uses WPF instead. Luckily Xamarin.Forms also supports WPF and WinForms. For WPF you can follow an official How To here: https://learn.microsoft.com/en-US/xamarin/xamarin-forms/platform/other/wpf .
Luckily for me I was planning on supporting Windows prior to windows 10 so it was a given that I had to switch.

Running exe in QtCreator has different working directory than outside QtCreator [duplicate]

This question already has answers here:
Used current working directory by mistake... Where the heck is my database?
(3 answers)
Closed 6 years ago.
when I compile and run an application inside QtCreator, the current working directory is the build directory, i.e. the folder named "build-MyProject-Desktop_Qt_5_4_0_MSVC2013_32bit" in my case, but this isn't the directory the exe resides in. The exe can be found in the debug or release subdirectory, which is the "current working directory" when I run the exe outside of QtCreator. How can I make QtCreator use this path as current working directory as well? I already tried to change the directory under "Projects" in my Run settings, but it looks like I can't use different directories for the debug and release builds.
edit: Calling this a duplicate is a bit far fetched in my opinion, because the "duplicate" refers to creating a DB, while mine refers to weird behavior from QtCreator. The question I actually asked was how to change QtCreator's properties, because it's weird to call my exe from a parent folder. Visual Studio never did that to me. The lesson (don't use the current working directory unless you explicitly set it) may be the same, but the questions were completely different, so I had no way of finding a solution to my problem by searching stackoverflow instead of asking.
If you want your program to always use the location of executable as its working directory, then you can just do that from inside the application code
QDir::setCurrent(QCoreApplication::applicationDirPath());
If you need to find files relative to your executable, it is not a good idea to rely on the Current Working Directory, which is determined by where your program is called from, not where the executable file lives.
To find the location of your executable, use QCoreApplication::applicationDirPath. Note that this is still a bit flaky with respect to cross-platform portability, as e.g. Unix or MacOS will tend to put files related to your program in radically different locations than on a Windows PC by convention.
If I call your program like this:
some/subdir/yourprogram
the current working directory will not be some/subdir, and your logic will fail.
As the oposite workAround proposed by Kevin Krammer, you can change the working directory outside Qt Creator :
Admitting this configuration :
C:\buildDir\debug
C:\buildDir\release
Make a batch in C:\buildDir\launch.bat (for exemple) which launches your executable : release\yourexe.exe
This batch can be use sooner or later to specify some useful environment variables or log redirections.
(PS : I suppose you are under Windows regarding your compiler, but this works similarly on linux)

JAVAFX not being picked up in runtime from Spring STS with Java 8 on Mac

I've installed Java 8 and Spring STS on Mac. Running jjs from the command line works. However, when trying to create a new class in a Maven project in STS, the editor doesn't recognise the javafx.* package automatically.
Attached you'll find an example of an image showing that the only Label object suggested is the java.awt one.
Any idea on how I could solve this?
Regards,
M.
I think this is related to the settings of your project. If your project is created with an execution environment JavaSE-1.8, this execution environment doesn't have the javafx API defined as accessible and you would need to manually allow that. If you choose the 1.8 JRE (as a JRE, not an execution environment) in your project settings, the JavaFX API is accessible and works nicely in content-assist, quick fix, etc. This is at least the case if you create a standard Java project.

What is assembly EnvDTE 8.0.0.0?

I made a small console app in VS 2010 and I just published it and went to install it on another pc (Win XP Sp3). The installer made me update the .Net framework, which I did and then when i went to run th second part which actually installs the app I am getting the following modal box:
Unable to install or run the application. the application requires that assembly EnvDTE Version 8.0.0.0 be installed in the Global Assembly cache (GAC) first.
Please contact your system administrator.
What in the world is EnvDTE v8.0.0.0????
This is a tiny app which does a small web call to an api and returns the results. I do make a DB call for a select and and update using some generated code from Codesmith/Nettiers (including enterprise Library). These files are referenced in the app though already.
Any ideas how to fix or work around this?
EnvDTE.dll is, as Zabba said in his comment (not sure why he didn't answer with this) used to automate Visual Studio. For some reason, you have added a reference to this in your project.
Open your solution, look at the References node in all your solution projects, and delete any reference pointing to EnvDTE.
It doesn't normally magically appear in your reference list; you either have to add it, or the project template you used to create your project referenced it, or you added an item whose template added this reference.

Running a JavaFX program within a web page, not launching a new window

I've seen lots of examples of JavaFX in my reading, but every JavaFX app I've seen need to be launched in a separate window. The apps don't run within a web page.
Can JavaFX applications be run within a web page, just like we would expect a Flash app (or, for that matter, an applet) to run? Is there a reason why people aren't letting JavaFX apps run within their web pages?
Is there a particular bit of HTML code that needs to be used to get a JavaFX app to run Flash/applet-style?
Yes, just build a demo JavaFX application in NetBeans. I'd be surprised if they didn't provide you with some type of 'Hello World' test app. Then take a look at the HTML page it creates.
If you run into problems getting your JavaFX app to run on a webpage, take a look at this question. The short story is that you can't just copy jar files and copy and paste the appropriate HTML into your webpage. You need to include the JNLP file NetBeans creates, and you have to edit some of the NetBeansy stuff in the JNLP file.
Yep, just use run application as Java Applet. NetBeans will deploy all FX stuff correctly for all platforms including Java Applet.
See....
http://www.javafx.com/samples/SimpleVideoPlayer/index.html
Yes you can do it.
Look for about JNLPAppletLauncher

Resources