使用javaFX 11定制jre [英] custom jre with javaFX 11

查看:409
本文介绍了使用javaFX 11定制jre的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JDK11和JavaFX11。

我使用Jlink为我的示例FX模块程序创建了一个自定义JRE,但是当我尝试使用自定义JRE运行时,它会产生如下错误:



这是我创建自定义JRE的方式(无错误)

  jlink --module-path .. \ jmods;%PATH_TO_FX%--add-modules java.base,java.desktop,jdk.unsupported,javafx.graphics --output FXJRE 

这是我尝试运行的方式(有错误)

  FXJRE\bin\java --module-path%PATH_TO_FX%; mods -m com.javafxdemo / com.javafxdemo.JavaFXDe​​mo 

错误消息:

 图形设备初始化失败:d3d,sw 
初始化QuantumRenderer时出错:找不到合适的管道
java.lang.RuntimeException:java.lang.RuntimeException:初始化QuantumRenderer时出错:在javafx.graphics / com.sun.javafx.tk找不到合适的管道
。 quantum.Quantu mRenderer.getInstance(QuantumRenderer.java:280)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:222)
at javafx.graphics/com。 sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:260)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
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 )
at java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base / jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base / java.lang.reflect.Method.invoke(Method.java:566)
在java.base / sun.launcher.LauncherHelper $ FXHelper.main(LauncherHelper.java:1051)
引起:java.lang.RuntimeException:初始化QuantumRenderer时出错:在javafx.graphics找不到合适的管道
/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer。 java:124)
at java.base / java.lang.Thread.run(Thread.java:834)
线程中的异常mainjava.lang.reflect.InvocationTargetException
at java .base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at jav a.base / jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base / java.lang.reflect.Method.invoke(Method.java:566)
at java.base / sun.launcher.LauncherHelper $ FXHelper.main(LauncherHelper.java:1051)
引起:java.lang.RuntimeException:没有工具包在javafx.graphics/com.sun.javafx找到
.tk.Toolkit.getToolkit(Toolkit.java:272)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
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更多

以下是我如何编译:
源JavaFXDe​​mo.java

  package com.javafxdemo; 

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

公共类JavaFXDe​​mo扩展Application {
@Override
public void start(Stage stage){
stage.setTitle(Hello World);
Group root = new Group();
场景场景=新场景(root,300,250);
Button btn = new Button();
btn.setLayoutX(100);
btn.setLayoutY(80);
btn.setText(Hello World);
btn.setOnAction(actionEvent - > System.out.println(Hello World));
root.getChildren()。add(btn);
stage.setScene(场景);
stage.show();
}

public static void main(String [] args){
launch(args);
}
}

module-info.java

  module com.javafxdemo {
需要javafx.base;
需要javafx.graphics;
需要javafx.controls;

出口com.javafxdemo;
}

这是我编译的方式。

  javac -d mods \ com.javafxdemo --module-path%PATH_TO_FX%src\com.javafxdemo\module-info.java src\com.javafxdemo \ com\javafxdemo \ JavaFXDe​​mo.java 

编译后,我有模块类文件如下:

 ├───mods$ b $b│└───com.javafxdemo$ b $b││模块 - info.class $ b $b││$ b $b│└───com$ b $b│└───javafxdemo$ b $b│JavaFXDe​​mo.class$ b $b│$ b $b└──── src $ b $b└───com.javafxdemo$ b $b│module-info.java$ b $b│$ b $b└───com$ b $b└───javafxdemo
JavaFXDe​​mo .java

我可以成功运行如下:

  java --module-path%PATH_TO_FX%; mods -m com.javafxdemo / com.jav afxdemo.JavaFXDe​​mo 

我可以使用默认的JDK11运行。



如何成功创建自定义JRE并使用它运行示例FX模块程序?

解决方案

如果你去看看这个



JavaFX SDK 是您正在使用的那个:

  export PATH_TO_FX = / path / to / javafx-sdk-11 / lib 

如果你检查 lib 下的文件,这些都是罐子。



另一边的JavaFX jmods 包含jmod格式。



如果您阅读 jmod 格式这里


对于大多数开发任务,包括在模块路径上部署模块或将模板发布到Maven存储库,继续将模块打包到模块化JAR文件中。 jmod 工具适用于具有本机库或其他配置文件的模块,或者用于将要使用jlink工具链接到运行时映像的模块。


换句话说,如果你使用 javac java 要运行您的jar或模块,您可以使用SDK,但如果您使用 jlink 来创建自定义JRE,则需要 jmod 版本。



下载完jmod后,解压缩并创建此变量:

  export PATH_TO_FX_JMOD = / path / to / javafx-jmods-11 / 

现在你可以创建JRE了:

  jlink --module-path%PATH_TO_FX_JMOD%; mods --add-modules = com.javafxdemo --output FXJRE 

并运行:

  FXJRE / bin / java -m com.javafxdemo / com.javafxdemo.JavaFXDe​​mo 


I'm Using JDK11 and JavaFX11.
I created a custom JRE for my sample FX module program using Jlink, but when I try to run with the custom JRE, it renders errors as below:

This is how I created my custom JRE (no errors)

jlink --module-path ..\jmods;%PATH_TO_FX% --add-modules java.base,java.desktop,jdk.unsupported,javafx.graphics --output FXJRE

This is how I tried to run (with errors)

FXJRE\bin\java --module-path %PATH_TO_FX%;mods -m com.javafxdemo/com.javafxdemo.JavaFXDemo

The error messages:

Graphics Device initialization failed for :  d3d, 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:280)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:222)
        at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:260)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
        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)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
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:94)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
        at java.base/java.lang.Thread.run(Thread.java:834)
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:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: No toolkit found
        at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
        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

Here is How I compiled: The source JavaFXDemo.java

package com.javafxdemo;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class JavaFXDemo extends Application {
    @Override
    public void start(Stage stage) {
        stage.setTitle("Hello World");
        Group root = new Group();
        Scene scene = new Scene(root, 300, 250);
        Button btn = new Button();
        btn.setLayoutX(100);
        btn.setLayoutY(80);
        btn.setText("Hello World");
        btn.setOnAction(actionEvent -> System.out.println("Hello World"));
        root.getChildren().add(btn);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

module-info.java

module com.javafxdemo {
    requires javafx.base;
    requires javafx.graphics;
    requires javafx.controls;

    exports com.javafxdemo;
}

This is how I compiled.

javac -d mods\com.javafxdemo --module-path %PATH_TO_FX% src\com.javafxdemo\module-info.java src\com.javafxdemo\com\javafxdemo\JavaFXDemo.java

After compilation, I have module class files as below:

├───mods
│   └───com.javafxdemo
│       │   module-info.class
│       │
│       └───com
│           └───javafxdemo
│                   JavaFXDemo.class
│
└───src
    └───com.javafxdemo
        │   module-info.java
        │
        └───com
            └───javafxdemo
                    JavaFXDemo.java

I can successfully run as below:

java --module-path %PATH_TO_FX%;mods -m com.javafxdemo/com.javafxdemo.JavaFXDemo

I can run with the default JDK11 though.

How can I successfully create a custom JRE and run the sample FX module program with it?

解决方案

If you go to this link, you will notice there are two flavors for the JavaFX distribution for each platform:

The JavaFX SDK is the one you are using as:

export PATH_TO_FX=/path/to/javafx-sdk-11/lib

and if you check the files under lib, these are jars.

The JavaFX jmods on the other side contains the jmod format.

And if you read about the jmod format here:

For most development tasks, including deploying modules on the module path or publishing them to a Maven repository, continue to package modules in modular JAR files. The jmod tool is intended for modules that have native libraries or other configuration files or for modules that you intend to link, with the jlink tool, to a runtime image.

In other words, if you use javac or java to run your jar or module you can use the SDK, but if you are using jlink to create a custom JRE, you need the jmod version.

Once you have downloaded the jmods, unzip them and create this variable:

export PATH_TO_FX_JMOD=/path/to/javafx-jmods-11/

Now you can create the JRE:

jlink --module-path %PATH_TO_FX_JMOD%;mods --add-modules=com.javafxdemo --output FXJRE

and run:

FXJRE/bin/java -m com.javafxdemo/com.javafxdemo.JavaFXDemo

这篇关于使用javaFX 11定制jre的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆