How can I access a correct version of a Java Desktop class - javafx

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.
At another answers I found out that by using Desktop.setOpenFileHandler(...) I can set the open file handler that will handle this event.
However, my version of Desktop does not have this option, it only has options to open, edit, print, mail or browse a file as can be seen from the allowed actions that are part of the Desktop class that I can access:
public static enum Action {
/**
* Represents an "open" action.
* #see Desktop#open(java.io.File)
*/
OPEN,
/**
* Represents an "edit" action.
* #see Desktop#edit(java.io.File)
*/
EDIT,
/**
* Represents a "print" action.
* #see Desktop#print(java.io.File)
*/
PRINT,
/**
* Represents a "mail" action.
* #see Desktop#mail()
* #see Desktop#mail(java.net.URI)
*/
MAIL,
/**
* Represents a "browse" action.
* #see Desktop#browse(java.net.URI)
*/
BROWSE
};
So my question is how can I get to the correct version of a Desktop class (my jre is jre 1.8.0_351).
And if that is not possible, can anyone propose another method for handling the event of opening a file by double clicking on it in Windows?
I first had Java 1.8.0_202, I updated to 1.8.0_351 to try to solve the problem, but that did not help.
I also tried to use the Application class to set event handler:
Application lowLevelApp = Application.GetApplication();
MyEventHandler eventhandler = new MyEventHandler(lowLevelApp);
eventhandler.setOpenFilesHandler(new MyHandleOpenFilesEvent());
lowLevelApp.setEventHandler(eventhandler);
but that did not work either.

Just by looking at the documentation of that method
https://docs.oracle.com/javase/9/docs/api/java/awt/desktop/OpenFilesHandler.html
you would see that this method was introduced in version 9 of Java. At the moment we are at version 19 so it is quite likely that some API between your 8 und the current 19 have changed. Just upgrade your Java and JavaFX and everything will be good.

Related

Upgrading Wicket 9.0.0 to 9.3.0: runtime error when try to access database

I am attempting to upgrade from Wicket 9.0.0 to Wicket 9.3.0. When I change the version in a quick-start application, everything is fine.
The problem occurs in my real application, where we were originally using Jakarta Enterprise Beans 8.0.0. At runtime, when a database access was attempted, we got an exception with the following message:
Last cause: net.sf.cglib.proxy.MethodInterceptor not found by org.objectweb.asm [23]
Trying to use Jakarta EE 9.1 instead
I changed my pom.xml as follows:
<jakartaee>9.1.0</jakartaee>
<wicket.version>9.3.0</wicket.version>
I downloaded the jar for Jakarta EE 9.1, changed "javax" to "jakarta" throughout my application, rebuilt it and tried to run again.
The result was still not perfect, but significantly better than before: a plain old null pointer exception instead of any weird errors about cglib.
Here's the section of code that now causes the trouble:
#EJB(name = "AdminNotesFacade")
private AdminNotesFacade adminNotesFacade;
public AdminNotesFacade getAdminNotesFacade() {
return adminNotesFacade; //ACTUALLY RETURNS NULL
}
So now the big question is: what do I need to do/change to make the #EJB work instead of returning null?
Checking the Payara log, I get this error:
java.lang.RuntimeException: Unable to load the EJB module. DeploymentContext does not contain any EJB. Check the archive to ensure correct packaging for D:\Dev\icase2\target\icase2.
If you use EJB component annotations to define the EJB, and an ejb or web deployment descriptor is also used, please make sure that the deployment descriptor references a Java EE 5 or higher version schema, and that the metadata-complete attribute is not set to true, so the component annotations can be processed as expected
at org.glassfish.ejb.startup.EjbDeployer.prepare(EjbDeployer.java:189)
Adding further details, 2022-05-06
I wonder if we were going off on the wrong track when we thought that we could fix this by upgrading our jakartaee version. From Wicket 9.0 to 9.3 is only a change of minor version and you wouldn't expect to have to make such fundamental changes to get a minor upgrade working.
I've tried using Wicket 9.9.1 instead, in case this problem has been fixed in more recent versions, but it's exactly the same.
Anyway, I have created a very small "quick-start" application, based on Wicket's own templates, to reproduce the problem. I have stuck with the original "javax" version, and added just one EJB - a JavaMail bean. I think it's probably interesting to know that it's not a specifically database-related issue. We just can't seem to load any EJBs at all.
In the Wicket 9.0.0 version, a simple form is displayed on the home page, allowing the user to enter their email address. When they submit the form, a test message is sent to that address. It works fine.
Then if I change the Wicket version to 9.3.0 but make no other changes at all, it doesn't even get to the stage of displaying the home page, it immediately crashes with the message "Last cause: net.sf.cglib.proxy.MethodInterceptor not found by org.objectweb.asm [23]"
For what it's worth, here's the code that triggers the error.
public class HomePage extends WebPage {
#EJB(name = "EmailerFacade")
private EmailerFacade emailerFacade;
private static final long serialVersionUID = 1L;
private String sendTo = "";
public HomePage(final PageParameters parameters) {
super(parameters);
add(new Label("version", getApplication()
.getFrameworkSettings().getVersion()));
FeedbackPanel feedback = new FeedbackPanel("feedback");
add(feedback);
final Form emailForm = new Form("emailForm") {
#Override
protected void onSubmit() {
emailerFacade.sendMessage(sendTo, "Test message from quick-start",
"Version is " + getApplication().getFrameworkSettings()
.getVersion());
info("Tried to send message to " + sendTo);
}
};
add(emailForm);
final TextField<String> emailAddress = new TextField<>("emailAddress",
new PropertyModel<>(this, "sendTo"));
emailAddress.setLabel(Model.of("Email address"));
emailAddress.setRequired(true);
emailForm.add(emailAddress);
}
}
Wicket 9.x is based on javax.servlet APIs. To deploy it on jakarta.servlet supporting web container you will need to migrate the bytecode with a tool like https://github.com/apache/tomcat-jakartaee-migration.
I am not sure whether Payara does something smart at runtime to support both javax.** and jakarta.** classes.
Tomcat 10.x supports migration of the classes at application start time by deploying your app in the special $CATALINA_HOME/webapps-javaee folder.
This answer was actually provided by Sven Meier. He commented:
Use the new system property to switch to ByteBuddy in Wicket 9.x:
-Dwicket.ioc.useByteBuddy=true
To expand a bit on this, I found I needed to do three things:
Set the system property "wicket.ioc.useByteBuddy" to true as specified by Sven
Add a dependency on byte buddy
Upgrade to a higher version than I was initially attempting to do: 9.3.0 was not good enough. I see in a comment above by Sven, he says that the migration to byte buddy was actually done in 9.5. So in fact I upgraded to the latest version, which is currently 9.9.1.
Here is the dependency on byte buddy that I added:
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.12.10</version>
</dependency>

Visibilty of private extensions on Visual Studio Marketplace

I have created some extensions which we will only use internally in our company. Therefore I have set the Extensions to private.
I assumed that this way the users added to the publisher as "reader" could see the lis of extensions when they use the link to the publisher (i.e. https://marketplace.visualstudio.com/publishers/CompanyXY)
I've noticed that this is not the case and if I want to make the extensions available to our developers I need to provide them the direct link to the extension (i.e. https://marketplace.visualstudio.com/items?itemName=CompanyXY.ExtensionXY).
Isn't there a way that I can make the whole list of private extensions available to the authorized users?
Any hint is highly appreciated.
Visibilty of private extensions on Visual Studio Marketplace
You should create a private gallery for VS extension and then put any private extensions on that gallery for internal developers to use. In this way, we can get a list of private extensions directly.
Visual Studio Marketplace is a public vs extension market. Although private packages can be added, there is no way to add private path to store private nuget packages for internal developers accessing. You have to search the private extensions based on your permission one by one and then install them. On that website, it does not support creating private pipeline which stores all your private extensions based on your requirements.
As a suggestion, you can create a private gallery as Sergey said. This is equivalent to creating a private pipeline for specific personnel to access, which stores any vs extensions you want to provide to internal developers.
1) create a shared folder that can access to your internal developers.
2) put any private vsix files into the folder
3) download PrivateGalleryCreator.exe and then copy PrivateGalleryCreator.exe into the folder.
4) click to run the PrivateGalleryCreator.exe on the folder to generate the feed.xml file.
5) enter Tools-->Options->Environment-->Extensions. Click Add, rename the new gallary and copy the full path of the feed.xml into URL.
Remember to click Apply to enable the URL. And let any of your internal developers add the file path from the private shared folder into their VS IDE to enable the gallery.
You can see a list of your private extensions and you can install any of them under it.
What if some developers have already installed the extension via
Marketplace? So they probably need to uninstal and install it again
from the private gallery.
If you want to enable the private gallery, you should first uninstall the installed private extensions on your VS IDE, remove them on the VS marketplace, instead, put them on the private gallery's folder and install them in that.
==================================
Private extensions under VS marketplace:
Regardless of whether private or public extensions are stored in a large container, the extensions can be seen according to the corresponding permissions. You need to manually query and install them one by one. You can never get a whole private package list.
Private gallery:
It is equivalent to creating a private container, storing all private extensions, and directly accessing the container to get a list of whole private extensions.
You can use a private gallery for extensions instead of the Marketplace: Private galleries.

How to access public download folder in every platform in Xamarin.Forms

I need to create a backup service so I intend to save the SQLite database file on each platform. The saved file should be available after the uninstall of the app.
I intend to use the Downloads folder (which should be available on every platform).
I have created an interface and use the following code per platform:
Interface:
public interface IBackupService
{
string GetDownloadPath();
}
Android:
public string GetDownloadPath()
{
return Android.OS.Environment.DirectoryDownloads;
}
UWP:
public string GetDownloadPath()
{
return Windows.Storage.KnownFolders.???????;
}
What should I do about that? Is there a public library that I could use?
There does not seem to be a general downloads folder as per this documentation on KnownFolders. So your assumption on the Downloads folder being on every platform doesn't seem to be correct.
If we dive in a bit further we get to the DocumentsLibrary which seems the obvious choice for this kind of purpose, but it is not. Microsoft says:
The Documents library is not intended for general use. For more info,
see App capability declarations. Also, see the following blog post.
Dealing with Documents: How (not) to use the documentsLibrary capability in Windows Store apps
The paragraph after that seems to describe what we have to do then;
If your app has to create and update files that only your app uses,
consider using the app's local folder. Get the app's local folder from
the Windows.Storage.ApplicationData.Current.LocalFolder property.
So, as I can extract from your question you only want to use storage for your app, so the Windows.Storage.ApplicationData.Current.LocalFolder seems to be the right choice according to Microsoft.

Symfony2: fetching data from database returns a "500 Internal Server Error"

I moved a project to a hosted webspace (at all-inkl, de) which worked well on my local computer. It's possible to access the project at intern.wir-sind-kirche.de and to successfully login. If I click onto a menuitem after logging in this results in a "500 Internal Server Error". It happens during this call:
$entities = $em->getRepository('LFToolsCRMBundle:Mailinglist')->findAll();
which is placed in an action to show all stored data of the named entity in a table.
It looks as if the database is ok as far as I'm able to login.
Both versions of the project, on my local computer and at the webspace as well are completly identical.
Thanks for any help and hints.
Instead of using absolute annotation name, import Doctrine\ORM\Mapping namespace as ORM and then use #ORM\Index:
use Doctrine\ORM\Mapping as ORM
// ...
class MyEntity
{
/**
* #ORM\Index(...)
*/
public $someProperty;
}
Note also that annotations are case-sensitive, so there is no #ORM\index, it is #ORM\Index.
You could have different behavior on various machines because of different php or bundles versions.
It is often a permission problem on the app/cache and/or app/log folders. But when developing you should always use /web/app_dev.php it has great debug tools and will tell you explicitly what the problem is instead of throwing a 500 error. Additionally you should read the documentation available here: http://symfony.com/doc/master/book/index.html

Reducing HtmlUnit Library jar size

Hi I have written a script using HTMLUnit that fetches a web page given a url and performs certain operations on them. For instance searching for a string on a page or clicking on a link and so on. I am creating a runnable jar using eclipse IDE.
HTML-Unit consists of about 21 different library jars that i am extracting in my single final runnable jar. These dependencies cause the single jar to occupy a space of about 9.3MB. I have been trying to reduce the individual jar size using obfuscation. I am using a tool called proguard for it.
Here is a sample proguard configuration i am using to obfuscate a single library jar by the name of "commons-logging-1.1.1.jar":
`-libraryjars <java.home>/lib/rt.jar
-injars C:/Users/Desktop/Jars/commons-logging-1.1.1.jar
-outjar C:/Users/Desktop/SmallJars/commons-logging-1.1.1.jar
-printmapping C:/Users/Desktop/SmallJars/out_commons-logging-1.1.1.map
-renamesourcefileattribute SourceFile
-dontnote
-keepattributes InnerClasses,SourceFile,LineNumberTable,Deprecated
-keep public class * {
public protected *;
}
-keepclassmembernames class * {
java.lang.Class class$(java.lang.String);
java.lang.Class class$(java.lang.String, boolean);
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers class * implements java.io.Serializable
{
static final long serialVersionUID;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}`
The config is pretty much the same as one given on the proguard website in usage -> typical libraries. On rebuilding the project in eclipse using these 21 reduced jars and running it, the script fails at runtime with the exception:
"java.lang.NoSuchMethodException: org.apache.http.conn.ssl.SSLSocketFactory.createDefaultSSLContext()"
Looks like i have obfuscated the individual jars in a manner that certain methods will now not be found. Could you guide me as to what may be causing these exceptions. and is there something wrong with the config file above.If
so what would be the best proguard configuration for this scenario.
I am aware another member was chasing a similar problem. The question is posted at link:
[a link] (Determine used libraries to reduce JAR file size)
Thank you!!
The method is accessed by reflection, which ProGuard can't know from its static analysis. You have to preserve it in your configuration. Cfr. ProGuard manual > Troubleshooting > NoSuchMethodException.
Processing the application as a whole will be much more effective than processing the libraries individually, because ProGuard may then remove entirely unused libraries or at least larger parts of them.

Resources