How to use JavaFX on M1 MacBook? - java

When attempting to run the following program, an error occurs.
jon#jonathans-mbp-4 lab4 % sysctl -a | grep brand
machdep.cpu.brand_string: Apple M1
jon#jonathans-mbp-4 lab4 % java --version
java 19.0.2 2023-01-17
Java(TM) SE Runtime Environment (build 19.0.2+7-44)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)
import javafx.application.Application;
public class App {
public static void main(String[] args) {
Application.launch(GUIApplication.class, args);
}
}
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class GUIApplication extends Application{
#Override
public void start(Stage stage) throws Exception {
// Fix weird font issue in dialog boxes on Macs
// Application.setUserAgentStylesheet(Application.STYLESHEET_MODENA);
// com.sun.javafx.css.StyleManager.getInstance().addUserAgentStylesheet("MainWindow.css");
var loader = new FXMLLoader(getClass().getResource("MainWindow.fxml"));
var scene = new Scene(loader.load());
stage.setScene(scene);
stage.setTitle("Hello"); // Title of main window
stage.show();
}
}
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
public class MainWindow {
#FXML
void onGreetClicked(ActionEvent event) {
var alert = new Alert(AlertType.INFORMATION, "Hello, world!");
alert.setHeaderText(null);
alert.show();
}
}
.root {
-fx-padding: 10; /* Add a small padding around the window */
-fx-font-family: 'Helvetica', Arial, sans-serif;
}
/* for Macs */
.dialog-pane {
-fx-font-family: 'Helvetica', Arial, sans-serif;
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox fx:controller="MainWindow" xmlns:fx="http://javafx.com/fxml" stylesheets="#MainWindow.css"
spacing="10" prefHeight="400" prefWidth="250">
<Button onAction="#onGreetClicked" text="Greet" />
</VBox>
jon#jonathans-mbp-4 lab4 % gradle clean install
> Configure project :
Project : => no module-info.java found
BUILD SUCCESSFUL in 782ms
6 actionable tasks: 6 executed
jon#jonathans-mbp-4 lab4 % gradle clean run
> Configure project :
Project : => no module-info.java found
> Task :run FAILED
Loading library prism_es2 from resource failed: java.lang.UnsatisfiedLinkError: /Users/jon/.openjfx/cache/17/libprism_es2.dylib: dlopen(/Users/jon/.openjfx/cache/17/libprism_es2.dylib, 0x0001): tried: '/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (no such file), '/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
java.lang.UnsatisfiedLinkError: /Users/jon/.openjfx/cache/17/libprism_es2.dylib: dlopen(/Users/jon/.openjfx/cache/17/libprism_es2.dylib, 0x0001): tried: '/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (no such file), '/Users/jon/.openjfx/cache/17/libprism_es2.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
at java.base/java.lang.Runtime.load0(Runtime.java:755)
at java.base/java.lang.System.load(System.java:1953)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.installLibraryFromResource(NativeLibLoader.java:217)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryFromResource(NativeLibLoader.java:197)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:138)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:54)
at javafx.graphics/com.sun.prism.es2.ES2Pipeline.lambda$static$0(ES2Pipeline.java:63)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at javafx.graphics/com.sun.prism.es2.ES2Pipeline.<clinit>(ES2Pipeline.java:52)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at javafx.graphics/com.sun.prism.GraphicsPipeline.createPipeline(GraphicsPipeline.java:218)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:92)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.base/java.lang.Thread.run(Thread.java:833)
Loading library prism_sw from resource failed: java.lang.UnsatisfiedLinkError: /Users/jon/.openjfx/cache/17/libprism_sw.dylib: dlopen(/Users/jon/.openjfx/cache/17/libprism_sw.dylib, 0x0001): tried: '/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (no such file), '/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
java.lang.UnsatisfiedLinkError: /Users/jon/.openjfx/cache/17/libprism_sw.dylib: dlopen(/Users/jon/.openjfx/cache/17/libprism_sw.dylib, 0x0001): tried: '/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (no such file), '/Users/jon/.openjfx/cache/17/libprism_sw.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
at java.base/java.lang.Runtime.load0(Runtime.java:755)
at java.base/java.lang.System.load(System.java:1953)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.installLibraryFromResource(NativeLibLoader.java:217)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryFromResource(NativeLibLoader.java:197)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:138)
at javafx.graphics/com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:54)
at javafx.graphics/com.sun.prism.sw.SWPipeline.lambda$static$0(SWPipeline.java:43)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at javafx.graphics/com.sun.prism.sw.SWPipeline.<clinit>(SWPipeline.java:42)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at javafx.graphics/com.sun.prism.GraphicsPipeline.createPipeline(GraphicsPipeline.java:218)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:92)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.base/java.lang.Thread.run(Thread.java:833)
Graphics Device initialization failed for : es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:283)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:254)
at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:264)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:291)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:163)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:659)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:679)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:95)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
... 1 more
Exception in thread "main" java.lang.RuntimeException: No toolkit found
at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:276)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:291)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:163)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:659)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:679)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/opt/homebrew/Cellar/openjdk#17/17.0.6/libexec/openjdk.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 777ms
5 actionable tasks: 5 executed
I have run the program from java to install Java 19 (my understanding is that uninstalls previous versions) and nothing changed. I manually deleted the JDKs (/Library/Java/JavaVirtualMachines) and reinstalled jdk-19.jdk.
If it's not obvious, I don't really know what I'm doing. I need to get JavaFX to work for a university lab.
The only other question I found said to reinstall Java, which I believe I did, but didn't fix the issue.

Just found this
I installed this
Not sure that this was the best solution (I don't really know what Azul is), but the program runs at least.

Related

How to launch JavaFX source code file from command line?

Since JDK 11, the java command can launch a java source code file, i.e. no need to first compile your java source code. Here is my java source code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class HelloJavaFxWorld extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Label label = new Label("Hello JavaFX World");
Pane root = new Pane(label);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I save this code as file HelloJavaFxWorld.java.
I open a command prompt window and enter the following command.
java HelloJavaFxWorld.java
This is (part of) the output.
HelloJavaFxWorld.java:1: error: package javafx.application does not exist
import javafx.application.Application;
How can I run a JavaFX source code file?
Since JDK 11 is modular, you need to add the JavaFX modules. Try the following.
java -p "path\to\javafx.graphics.jar;path\to\javafx.base.jar;path\to\javafx.controls.jar" --add-modules javafx.graphics,javafx.controls HelloJavaFxWorld.java
Replace path\to with the actual path to the JAR files. For example on my Windows 10 machine I have installed JDK 16.0.1 so I am using JavaFX 16 and have placed the [JavaFX] JAR files in this folder:
C:\Program Files\Java\javafx-sdk-16\lib
So my actual command for launching the JavaFX source code file is:
java -p "C:\Program Files\Java\javafx-sdk-16\lib\javafx.graphics.jar;C:\Program Files\Java\javafx-sdk-16\lib\javafx.base.jar;C:\Program Files\Java\javafx-sdk-16\lib\javafx.controls.jar" --add-modules javafx.graphics,javafx.controls HelloJavaFxWorld.java
Note that instead of -p, you can use --module-path. Then the command becomes:
java --module-path "C:\Program Files\Java\javafx-sdk-16\lib" --add-modules javafx.graphics,javafx.controls HelloJavaFxWorld.java
Note that I enter that command from the folder containing the java source code file.
The above command may result in the following exception.
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: HelloJavaFxWorld
at javafx.graphics/javafx.application.Application.launch(Application.java:310)
at HelloJavaFxWorld.main(HelloJavaFxWorld.java:19)
Caused by: java.lang.ClassNotFoundException: HelloJavaFxWorld
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:466)
at javafx.graphics/javafx.application.Application.launch(Application.java:298)
at HelloJavaFxWorld.main(HelloJavaFxWorld.java:19)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:415)
at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:192)
at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:132)
This is because, when launching a java source code file, the source code is compiled and the compiled class is stored in memory, i.e. no .class file is created. Method launch(String...), in class javafx.application.Application, calls method forName, in class java.lang.Class in order to load the JavaFX application class. Since there is no HelloJavaFxWorld.class file, method forName throws ClassNotFoundException.
In order to fix that, simply change your java source code to call the other launch method. In other words, change method main to the following.
public static void main(String[] args) {
launch(HelloJavaFxWorld.class, args);
}
Now, when I enter the above java command, I get the following window.

iTMSTransporter: "Could not find or load main class" when launched

I'm trying to notarize a DMG via "xcrun altool" in Terminal but it fails with the output below.
In fact it even running iTMSTransporter directly it crashes:
/Applications/Xcode.app/Contents/SharedFrameworks/ContentDeliveryServices.framework/Versions/A/itms/bin/iTMSTransporter
Error: Could not find or load main class 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:.
Caused by: java.lang.ClassNotFoundException: 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:.
What I have done to troublehshoot:
Updated to Xcode 12.3
Updated and installed latest commandline tools for Xcode
Tried two different SDK/JDK/JRE versions of Java, currently using java 15.0.1 2020-10-20
Java(TM) SE Runtime Environment (build 15.0.1+9-18)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
Tried declaring JAVA_HOME
Looked for iTMSTransporter cache file or folder (in case sensitive and lowercase) in /, ~/ and /Library and ~/Library ~/.itmstransporter in order ot delete it, there is none.
I'm on macOS Big Sur 11.1
I have never had two name versions of Xcode, so I have not had a different name for the app. I tried renaming it for troubleshooting and reverting back to original Xcode name but this also did not help.
Tried reinstalling iTMSTransporter
Error output below:
2020-12-24 10:39:03.442 altool[10776:511525] Sending request to iTunesTransporter…
2020-12-24 10:39:03.442 altool[10776:511525] Command: /usr/local/itms/bin/iTMSTransporter
2020-12-24 10:39:03.442 altool[10776:511525] Arguments: -m upload -u 'XXX' -vp json -DTxHeaders=XXX= -sessionid #env:XXX -sharedsecret #env:XXX -itc_provider '-f' -f '/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/XXX-72174C6DE294/com.XXX.XXX.itmsp' -indicator true -v eXtreme -Dtransporter.client='altool' -Dtransporter.client.version='4.029 (1194)'
2020-12-24 10:39:04.331 altool[10776:511518] Error: Could not find or load main class 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:.
2020-12-24 10:39:04.331 altool[10776:511518] Caused by: java.lang.ClassNotFoundException: 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:.
2020-12-24 10:39:04.336 altool[10776:511525] Error:
Error: Could not find or load main class 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:.
Caused by: java.lang.ClassNotFoundException: 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:.
2020-12-24 10:39:04.336 altool[10776:511525] Out:
2020-12-24 10:39:04.337 altool[10776:511525] Errors: (
"Error Domain=ITunesTransporterErrorDomain Code=-18000 \"Could not find or load main class 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:.\" UserInfo={NSLocalizedRecoverySuggestion=Could not find or load main class 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:., NSLocalizedDescription=Could not find or load main class 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:., NSLocalizedFailureReason=Could not find or load main class 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:.}"
)
2020-12-24 10:39:04.378 altool[10776:511518] *** Error: Unable to notarize app.
2020-12-24 10:39:04.378 altool[10776:511518] *** Error: code -18000 (Could not find or load main class 1.Library.Java.Extensions:.Library.Java.Extensions:.Network.Library.Java.Extensions:.System.Library.Java.Extensions:.usr.lib.java:.)
Issue was fixed after commenting out the line starting with:
JVM_LIB_PATH
in:
/usr/local/itms/bin/iTMSTransporter
It seems the way this line was setting the java related paths to iTMSTransporter was causing it to look in wrong places.
After commenting out this line iTMSTransporter reconfigured itself during launch and notarization submission was successful.

InternalError running JavaFX 15 application on Windows Subsystem for Linux

I am stuck when trying to run JavaFX 15 applications on Windows Subsystem for Linux WSL2 / Ubuntu 20.04, and need suggestions on the next steps to try.
So far I have been able to run all my Java builds I normally do on Windows/JDK15 inside WSL including those with Swing / AWT dependencies. The AWT / Swing test applications run successfully within WSL and reference JDK15, and running X Windows on Windows 10. However I cannot get any JavaFX application to run, even the HelloFX sample:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloFX extends Application {
public void start(Stage stage) {
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
Scene scene = new Scene(new StackPane(l), 640, 480);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
I've tried various X servers on Windows - X/Cygwin, X410, VcXsrv and XMing. Here is error message when running HelloFX with VcXsrv:
> echo $PATH_TO_FX
/mnt/c/linux/javafx-sdk-15/lib
> $JAVA_HOME/bin/java -version
openjdk version "15" 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)
> $JAVA_HOME/bin/java --module-path $PATH_TO_FX --add-modules javafx.controls -cp build/classes HelloFX
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Prism-ES2 Error : GL_VERSION (major.minor) = 1.4
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.UnsupportedOperationException: Internal Error
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$new$6(GtkApplication.java:189)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:171)
at javafx.graphics/com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
at javafx.graphics/com.sun.glass.ui.Application.run(Application.java:144)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:280)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:269)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
... 5 more
Some other sites such as How to set up working X11 forwarding on WSL2
mention the use of export LIBGL_ALWAYS_INDIRECT=1. With this setting, the 2 libGL error messages aren't printed but I get the same error stack.
A swing/AWT java app run from the same bash with the same DISPLAY runs fine with no errors. I am using the OpenJDK15 Linux and Gluon JavaFX 15. I've also tried jlink to make JRE with JDK15 and JavaFX modules - the same error message.
As suggested, when running with -Djdk.gtk.verbose=true the following messages appear:
checking GTK version 3
trying GTK library libgtk-3.so.0
trying GTK library libgtk-3.so
trying GTK library libgtk-x11-2.0.so.0
trying GTK library libgtk-x11-2.0.so
Thanks for the comments #José Pereda and #mipa which helped me towards a fix, adding libgtk-3
sudo apt install libgtk-3-0

java.lang.ClassNotFoundException when running trying to open android emulator with appium

I am trying to run the following code from Windows in Eclipse and finding the error that I've mentioned in the Title. Can anybody please suggest me.
Code:
package com.apanp.one;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
public class base {
public static void main(String[] args) throws MalformedURLException {
File f = new File("src");
File fs =new File(f,"original.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Shayan");
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
AndroidDriver<AndroidElement> driver = new AndroidDriver <> (new URL("http://127.0.0.1/wd/hub"), cap);
}
}
Error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at com.apanp.one.base.main(base.java:24)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 10 more
AVDManager
Config:
JDK
JAVA_HOME:C:\Program Files\Java\jdk-14.0.1
Java bin: C:\Program Files\Java\jdk-14.0.1\bin
ANDROID STUDIO DOWNLOAD:https://developer.android.com/studio
ANDROID_HOME=C:\Users\Shahid\AppData\Local\Android\Sdk
ANDROID-TOOLS-PATH:C:\Users\Shahid\AppData\Local\Android\Sdk\tools
ANDROID-TOOLS-BIN PATH: C:\Users\Shahid\AppData\Local\Android\Sdk\tools\bin
ANDROID-PLATFORM-PATH:C:\Users\Shahid\AppData\Local\Android\Sdk\platform-tools
CREATE ANDROID EMULATOR IN AVD MANAGER
WE CAN INVOKE EMULATOR THROUGH COMMAND PROMPT:C:\Users\Shahid\AppData\Local\Android\Sdk\emulator
THEN TYPE:emulator -avd Shayan
INSTALL node.js:https://nodejs.org/en/download/
NODE_HOME:C:\Program Files\nodejs
NPM_HOME:C:\Program Files\nodejs\node_modules\npm\bin
INSTALL APPIUM SERVER(using npm through command prompt): npm install -g appium
SOME COMMANDS WITH APPIUM SERVER:
-to start appium server: appium
-to close appium server: ctrl + C; Y/N-> y and ENTER
-to check version:appium --version
-to check where it is: where appium
INSTALL APPIUM JAVA CLIENT LIBRARY:http://appium.io/downloads.html; SELECT JAVA; SELECT JAR
DOWNLOAD ECLIPSE:https://www.eclipse.org/downloads/download.php?file=/oomph/epp/2020-03/R/eclipse-inst-win64.exe
ClassNotFoundException means you don’t have any class in your classpath to address this com/google/common/base/Function that means you are missing this class which belongs to guava dependency/jar in your project. Please add below dependency if you are using maven
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
<!-- or, for Android: -->
<version>23.6-android</version>
</dependency>
For java:
You can download jar file and keep it on class path

Phantom UnsatisfiedLinkError (openCV + JAVA) appears in console but not in IDE

There is an issue running openCV 3.1(Also tried with 3.0) in Windows7 x64 from console.
Sample code is this one:
package com.company;
import org.opencv.core.Core;
import org.opencv.core.Mat;
public class Main {
public static void main(String[] args) {
// write your code here
System.out.println("Entering Main");
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("Creating Mat");
new Mat();
System.out.println("Finished successfully");
}
}
I can run this project in IDEA IDE without any problems. Full output:
"C:\Program Files\Java\jdk1.8.0_102\bin\java" -Dvisualvm.id=11658625891829 -Djava.library.path=D:\opencv310\opencv\build\java -Didea.launcher.port=7536 "-Didea.launcher.bin.path=D:\progs\IntelliJ IDEA 14.1.4\bin" -Dfile.encoding=windows-1252 -classpath "C:\Program Files\Java\jdk1.8.0_102\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\zipfs.jar;C:\Users\mrk\IdeaProjects\TestOpencvError\out\production\TestOpencvError;D:\opencv310\opencv\build\java\opencv-310.jar;D:\progs\IntelliJ IDEA 14.1.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.company.Main
Entering Main
Creating Mat
Finished successfully
Process finished with exit code 0
But when I compile the source and try to launch .class from console
java -Djava.library.path=D:\ com.company.Main
(I have copied opencv310.dll to root of my D drive and jar file to java/lib/ext to be sure it is found)
I get the following output:
Entering Main
Creating Mat
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n
_Mat()J
at org.opencv.core.Mat.n_Mat(Native Method)
at org.opencv.core.Mat.(Mat.java:24)
at com.company.Main.main(Main.java:13)
Which means that DLL is loaded but there is no method n_Mat found. As a proof, when launched without the -Djava.library.path flag the output changes to the following
Entering Main
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java310 in
java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.company.Main.main(Main.java:11)
I have tried to launch the app with IDEA's parameters, that is
java -Dvisualvm.id=11658625891829 -Djava.library.path=D:\opencv310\opencv\build\java -Didea.launcher.port=7536 "-Didea.launcher.bin.path=D:\progs\IntelliJ IDEA 14.1.4\bin" -Dfile.encoding=windows-1252 -classpath "C:\Program Files\Java\jdk1.8.0_102\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\zipfs.jar;C:\Users\mrk\IdeaProjects\TestOpencvError\out\production\TestOpencvError;D:\opencv310\opencv\build\java\opencv-310.jar;D:\progs\IntelliJ IDEA 14.1.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.company.Main
but still got the same error.
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n
_Mat()J
at org.opencv.core.Mat.n_Mat(Native Method)
at org.opencv.core.Mat.(Mat.java:24)
at com.company.Main.main(Main.java:13)
I want to stress once again: code works fine when is being run from within the IDE. The error only shows in console.
There are several similar topics on the net but generally it is the missed -D*library flag issue. I have shown that it is not the case for me
OpenCV + Java = UnsatisfiedLinkError
Javacv UnsatisfiedLinkError in windows 7
This topic has a link to probably solve the issue using javah tool but I don't find it appropriate for my case since launching from IDE works without correcting headers.
UnsatisfiedLInkError Eclipse JNI (works from command line but not in Eclipse) package names
I have tried building jar in IDEA too but it resulted in the same error
What steps could I try to get the code running from the console?
What is that extra-something that is being done by IDE that is hidden from the user which makes this big difference?

Categories