bell-sw / Liberica

Free and 100% open source Progressive Java Runtime for modern Java™ deployments supported by a leading OpenJDK contributor
https://bell-sw.com/pages/libericajdk/
GNU General Public License v2.0
299 stars 28 forks source link

JavaFX Headless on Windows #113

Open java71 opened 1 year ago

java71 commented 1 year ago

Hi,

I am developping a server application that processed images : creating bitmap images for instance... Of course, my objective is to get a cross-platform single jar file! I use Full LIBERICA NIK v22.3 on WINDOWS 11.

Everything works well when I use standard Liberica native image on Windows but fails on LINUX because of 'no display' ! So, if my understanding is correct, I need to use JavaFX with spcial 'MONOCLE' configuration...

Again, if my reading is correct I can use MONOCLE configuration by applying arguments as follows -Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw

But it fails ! Error is "Failed to load Glass factory class".

So my questions are :

Thanks a lot for your help

AlexanderScherbatiy commented 1 year ago

Liberica jdk contains monocle only for Linux arm32 platform. For example, bellsoft-jdk17.0.6+10-linux-arm32-vfp-hflt-full.tar.gz includes the following monocle shared libraries:

ls jdk-17.0.6-full/lib/lib*monocle*
jdk-17.0.6-full/lib/libglass_monocle_epd.so 
jdk-17.0.6-full/lib/libglass_monocle_x11.so
jdk-17.0.6-full/lib/libglass_monocle.so 
jdk-17.0.6-full/lib/libprism_es2_monocle.so

One way to run JavaFX applications without display on Linux is using X virtual framebuffer. In docker it looks like:

docker pull winstonpro/ubuntu-desktop
docker run --rm -v /tmp/mount:/root/mount -it winstonpro/ubuntu-desktop bash
docker ps
docker exec -it <container-id> bash
apt update
apt  install -y mesa-utils and libgl1-mesa-glx
apt install xvfb
Xvfb :99 &
export DISPLAY=:99
jdk-11.0.18-full/bin/java  -Dprism.order=sw HelloWorld
java71 commented 1 year ago

Thanks for your reply ! By the way, my objective is to use NIK (native-image) in order to have a single executable file gathering whole project... Is there any plan/roadmap for integrating MONOCLE into LIBERICA for other platform ?

java71 commented 1 week ago

Hi Alexander,Sorry for coming back to you but I still cannot build a static image with NIK.And the problem can be produced with a very simple program.Everything is OK until LINK command (last step).After searching, it seems that '.a' libraries cannot be found.Could you please tell me what is realy needed for NIK to work ?The test I want to make is - to start from a virgin new LINUX install WITHOUT any other tools installed !- to install all packages/tools needed by NIK- put my 'jar' file and process the command for STATIC image.Do you have this kind of test integrated in yout development platform ?I precise that everything is OK from WINDOWS.I cannot believe that it is not possible to build such a static image from LINUX.Thank you for precising the packages needed for NIK....And please, make this test to start from a pure empty DEBIAN distribution for instance to check that hereafter program cannot be processed...Many thanks for your kind help ! Best regards,gilles---------------------------------------------------------------------------------------------import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.layout.StackPane;import javafx.stage.Stage; public class SampleFx extends Application {  public static void main(String[] args) {       launch(args);  }    @Override  public void start(Stage primaryStage) {       primaryStage.setTitle("Hello World!");       Button btn = new Button();       btn.setText("Say 'Hello World'");       btn.setOnAction(new EventHandler() {           @Override           public void handle(ActionEvent event) {               System.out.println("Hello World!");           }      });          StackPane root = new StackPane();       root.getChildren().add(btn);       primaryStage.setScene(new Scene(root, 300, 250));       primaryStage.show();     }}---------------------------------------------------------------------------------------------Message ID: @.***>