InternalError running JavaFX 15 application on Windows Subsystem for Linux - java

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

Related

Installing OpenCV On M1 / Apple Silicon MacOS Error. UnsatisfiedLinkError: no opencv_java460 in java.library.path

I am trying to install opencv on my new Macos M1 Macbook Air and want to use it on Intellij IDEA with Java language and Maven
I have followed this tutorial on yt : https://www.youtube.com/watch?v=68IrlXObQyE
I have installed xcode, clt, using brew and ant to download opencv, and add it to my project modules on intellij;
this is the error i got:
/Users/arkan/Library/Java/JavaVirtualMachines/openjdk-19.0.1/Contents/Home/bin/java -Djava.library.path=/opt/homebrew/Cellar/opencv/4.6.0_1/share/java/opencv4 -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=52948:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath /Users/arkan/Stash/Idea Project/CV/target/classes:/opt/homebrew/Cellar/opencv/4.6.0_1/share/java/opencv4/opencv-460.jar org.example.Main
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java460 in java.library.path: /opt/homebrew/Cellar/opencv/4.6.0_1/share/java/opencv4
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2444)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:848)
at java.base/java.lang.System.loadLibrary(System.java:2047)
at org.example.Main.<clinit>(Main.java:8)
Process finished with exit code 1
This is my source code:
package org.example;
import org.opencv.core.Core;
public class Main {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
System.out.println("Welcome to OpenCV " + Core.VERSION) ;
}
}
My current hypotesis is that i think this error is because the homebrew path on this M1 machine is different unlike the past machine. On the tutorial i watched the path to the .jar was /usr/opt/Cellar/ but mine is /opt/homebrew/Cellar/

Compilation failed: Subprocess failed

brew install leiningen
I got
Compiling joy.gui.DynaFrame
Could not locate joy/gui/DynaFrame__init.class or joy/gui/DynaFrame.clj on classpath:
Exception in thread "main" java.io.FileNotFoundException: Could not locate joy/gui/DynaFrame__init.class or joy/gui/DynaFrame.clj on classpath: , compiling:(/private/var/folders/zm/swyymlvn4l7__d1rln_n391r0000gn/T/form-init7580966196782799989.clj:1:124)
at clojure.lang.Compiler.load(Compiler.java:7142)
at clojure.lang.Compiler.loadFile(Compiler.java:7086)
at clojure.main$load_script.invoke(main.clj:274)
at clojure.main$init_opt.invoke(main.clj:279)
at clojure.main$initialize.invoke(main.clj:307)
at clojure.main$null_opt.invoke(main.clj:342)
at clojure.main$main.doInvoke(main.clj:420)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.io.FileNotFoundException: Could not locate joy/gui/DynaFrame__init.class or joy/gui/DynaFrame.clj on classpath:
at clojure.lang.RT.load(RT.java:443)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5066.invoke(core.clj:5641)
at clojure.core$load.doInvoke(core.clj:5640)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5446)
at clojure.core$compile$fn__5071.invoke(core.clj:5652)
at clojure.core$compile.invoke(core.clj:5651)
at user$eval20$fn__29.invoke(form-init7580966196782799989.clj:1)
at user$eval20.invoke(form-init7580966196782799989.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6703)
at clojure.lang.Compiler.eval(Compiler.java:6693)
at clojure.lang.Compiler.eval(Compiler.java:6693)
at clojure.lang.Compiler.load(Compiler.java:7130)
... 11 more
Compilation failed: Subprocess failed
I tried to reinstall but the issue does not solved.
When I type,
lein version
I got this:
Leiningen 2.9.1 on Java 12 Java HotSpot(TM) 64-Bit Server VM
I installed Java correctly but not sure where to start to fix this problem.
I looked around and it seems you are trying to run an old example from The Joy of Clojure, right?
The example needed a minor touch-up for me to be able to run it.
I created a new Leiningen project first with lein new app dynademo.
Inside the new project folder, I created the directories for the namespace: mkdir -p src/joy/gui
Created the file src/joy/gui/DynaFrame.clj
The Leiningen project that we just created with lein new ... uses Clojure 1.10, which doesn't seem to like one thing:
Replace the line with :prefix df- with :prefix "df-" (eg. wrap the value df- in quotes)
Save the file, and now you can launch the window from the REPL, like this:
$ lein repl
nREPL server started on port 44037 on host 127.0.0.1 - nrepl://127.0.0.1:44037
REPL-y 0.4.3, nREPL 0.6.0
Clojure 1.10.0
OpenJDK 64-Bit Server VM 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)
Results: Stored in vars *1, *2, *3, an exception in *e
dynaframe.core=> (compile 'joy.gui.DynaFrame)
joy.gui.DynaFrame
dynaframe.core=> (def hello-frame (joy.gui.DynaFrame. "Hello"))
#'dynaframe.core/hello-frame
dynaframe.core=> (.show hello-frame)
nil
It looks like this:
(you will need to move/resize the window a bit, but you get the idea). Note: I'm using Java 8 (JDK 1.8.0_191) but it should work the same in JDK 12.

java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable

I have been trying to run a Java AWT based application on an Ubuntu VM inside Docker. The application is a very simple one and it flawlessly runs on Windows through Eclipse. It simply opens up a window and prints hello world!. In fact when I export the jar file in to an Ubuntu VM that is running on my Windows host also gives me the same output as Windows when I run the jar file through “java -jar JFrameDocker.jar”.
However the story is not same when I try to run it inside docker. The instructions that I have specified in the Dockerfile executes without any error but when I run the application it throws
“java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable” . Trust me guys, I have tried many a times to resolve it but no luck till now.
Like setting the DISPLAY variable value multiple times, starting X server using xterm and xeyes, going through every possible article that I found on the Web. But nothing seems to be working here. I am providing all my files here that could get you a better understanding of my problem.
By the way this doesn't answer my question as same error is being thrown even after making the changes.
This is my java file.
package com.etp;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JFrameDockerTest {
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JLabel lable = new JLabel("Hello World");
panel.setLayout( new FlowLayout() );
frame.add(panel);
panel.add(lable);
frame.setVisible(true);
frame.setSize(800, 600);
}
}
This is my Dockerfile:
FROM java:8
ENV DISPLAY :0
ADD JFrameDocker.jar JFrameDocker.jar
CMD ["java","-jar", "JFrameDocker.jar"]
I have used below docker commands to build image and run it.
Docker Build : sudo docker build -t jframedocker .
Docker Run : sudo docker run jframedocker
Output Without Error Screenshot: (Without Docker)
Output with Docker:
etp#etp-VirtualBox:~/Downloads/JFrameDocker$ sudo docker run jframedocker
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at java.awt.Window.initGC(Window.java:475)
at java.awt.Window.init(Window.java:495)
at java.awt.Window.<init>(Window.java:537)
at java.awt.Frame.<init>(Frame.java:420)
at java.awt.Frame.<init>(Frame.java:385)
at javax.swing.JFrame.<init>(JFrame.java:189)
at com.etp.JFrameDockerTest.main(JFrameDockerTest.java:12)
... 5 more
You are using java:8 base image which most likely doesn't provide a graphical environment.
You can use ubuntu:18.04 base image with manually installed openjdk-11-jdk and xvfb packages. The xvfb-run command will take care of setting up the virtual X Server environment:
xvfb-run sets up an X authority file (or uses an existing user-specified one), writes a cookie to it (see xauth(1x)) and then starts the Xvfb X server as a background process. The process ID of Xvfb is stored for later use. The specified command is then run using the X display corresponding to the Xvfb server just started and the X authority file created earlier.
Dockerfile
FROM ubuntu:18.04
RUN apt-get update -y && apt-get upgrade -y && apt-get install -y openjdk-11-jdk xvfb
ADD JFrameDocker.java MANIFEST.mf ./
RUN javac JFrameDocker.java
RUN jar cfm JFrameDocker.jar MANIFEST.mf JFrameDocker.class
RUN xvfb-run java -jar JFrameDocker.jar
JFrameDocker.java
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JFrameDocker {
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JLabel lable = new JLabel("Hello World");
panel.setLayout(new FlowLayout());
frame.add(panel);
panel.add(lable);
frame.setSize(800, 600);
frame.setVisible(true);
System.out.println("Up and running");
}
}
MANIFEST.mf
Manifest-Version: 1.0
Main-Class: JFrameDocker

Where do I find start in gradlew in Eclipse?

package speedychris2.Cheerio;
import cpw.mods.fml.common.Mod;
#Mod(modid = "Mod", name = "Mod", version = "1.0")
public class Cheerio {
}
This is the error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at GradleStart.main(GradleStart.java:59)
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
When I click on (GradleStart.java:59) It brings up a window telling me that 59 is not a valid line number in gradlestart then prompts me to attach a source, which of course I don't know. This is in eclipse with Forge ModLoader for Minecraft. I was following these videos, and it gave me an error.
Any help?

Compiling and running with JavaFX 2.1

I am trying a very simple use of JavaFX using a simple set of lines of code which I got from another stackoverflow page (here). But, the problem is clearly not with that code but with something more fundamental in the build and run process.
Here is my code:
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
.
.
.
Media medMsg = new Media("msg.mp3");
MediaPlayer medplMsg = new MediaPlayer(medMsg);
medplMsg.play();
At first I couldn't get this to compile at all. Eventually I figured out that I needed to put -classpath c:\Program Files\Oracle\JavaFX 2.1 SDK\lib\rt\jfxrt.jar on my javac command line. (One obvious complex of questions here is: Why isn't it documented in any obvious place (1) that this is needed and (2) how exactly to figure out what the path to the JavaFX installation is?!)
But, when I run the code I get:
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/scene/media/Media
at progtest.main(progtest.java:120)
Caused by: java.lang.ClassNotFoundException: javafx.scene.media.Media
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
What does this mean? It looks like it doesn't know, at runtime, how to find the class javafx.scene.media.Media. But, my %CLASSPATH% variable definitely has "c:\Program Files\Oracle\JavaFX 2.1 SDK\lib\rt\jfxrt.jar" in it.
Any ideas? Thank you in advance!
This question somewhat duplicates compile javafx 2.0 manually.
This answer is specifically for JavaFX 2 versions before the release of Oracle Java 8. For Oracle JavaFX 8+, the JavaFX runtime is on the classpath, so you don't need to explicitly add it when compiling or JavaFX running applications.
Java includes JavaFX in jdk7u6 and above (for Windows and Linux) and jdk7u4 and above (for OSX).
Download and use jdk7u6+ and you won't need to specify the jfxrt.jar file in any classpath and all of your JavaFX related classpath issues should go away.
Here is a link to an early binary build of jdk7u6.
For JavaFX 2.1 on Windows you do need to include the jfxrt.jar lib in your classpath for compile (NetBeans will do this automatically if you use it's JavaFX platform settings) and (if you haven't packaged your app correctly using the javafxpackager or JavaFX ant tasks), also at runtime.
JavaFX 2.1 for Linux is a pre-release (in case you are using that). For the Linux pre-release you would only have to include jfxrt.jar in your classpath at both compile and runtime if the JavaFX runtime on Linux was not set up correctly.
Here is an example of a command line compilation and execution of a JavaFX program under windows.
Launch an editor:
C:\dev\test>notepad HelloWorld.java
Paste the following code and save it:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) {
stage.setScene(new Scene(new Label("Hello World")));
stage.show();
}
}
Compile and run it JavaFX 2.2:
C:\dev\test>javac -cp "\Program Files\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar" HelloWorld.java
C:\dev\test>java -cp ".;\Program Files\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar" HelloWorld
For Oracle Java 8+, the explicit JavaFX classpath specifier is not required:
C:\dev\test>javac HelloWorld.java
C:\dev\test>java HelloWorld
Note that usually rather than just compiling the code and running it, you would also package the code with javafxpackager or the javafx ant tasks. These tasks will embed a launcher class into your packaged app which will detect the version and location of the JavaFX runtime so that you don't need to specify the jfxrt.jar location unless you want to override the default location for the platform.
For Java 7 update 21, Windows XP SP3, I used
javac -cp "\Program Files\Java\jre7\lib\jfxrt.jar" HelloWorld.java
and
java -cp ".;\Program Files\Java\jre7\lib\jfxrt.jar" HelloWorld

Categories