在活动 JDK 中找不到 JavaFX 部署库 [英] JavaFX deployment library not found in active JDK

查看:21
本文介绍了在活动 JDK 中找不到 JavaFX 部署库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迁移到 OpenJDK 11 和 OpenJFX 11.我已经成功地从源代码构建了这两个版本,并且根据 OpenJFX wiki 使用 --with-import-modules=[path_to_modular_sdk] arg 来构建 JDK.一切顺利,直到我尝试在 Apache Netbeans 9 中构建一个简单的Hello World"测试项目;此时我收到以下错误:在活动 JDK 中未找到 JavaFX 部署库".尝试搜索有关此的信息,但找不到任何相关信息.如果有人能阐明导致这种情况的原因,我将不胜感激.谢谢你的帮助.帕特里克.

解决方案

正如@mipa 指出的那样,您无需构建 Java 11 或 JavaFX 11 即可迁移现有项目.

至于 Apache NetBeans 9.0,JavaFX 项目的当前 ant 构建文件尚不支持 JavaFX 11.它一直在寻找JavaFX jar,找不到就会停止.这是过去(Java 8 之前)的遗留问题,当时 JavaFX 不是 JDK 的一部分,您必须手动添加 jar.

例如,当您尝试创建一个新的 JavaFX 项目时,您将收到此错误:

但这并不意味着您不能运行 JavaFX 11,无论有没有 NetBeans 9.0.

在终端上运行

您可以从终端运行 Java/JavaFX 11 项目.您可以按照此

这个库就是我本地下载的JavaFX下的文件夹:/Users//Downloads/javafx-sdk-11/lib/.当然,如果你自己构建了它,你可以指向那个位置.

现在我可以定义模块了:

module javafx11 {需要 javafx.controls;导出 javafx11;}

并将上述 HelloFX 类添加到 javafx11 包中.

现在项目将完美运行.

即使您仍在使用 ant,在这种情况下,构建文件也会更新为模块路径更改,并且没有任何特定于 JavaFX 的内容,因此项目运行没有任何问题.

Java 项目

如果模块化项目有效,那么常规Java 项目也可以在 NetBeans 9.0 上运行.

创建一个 Java 项目(同样,不是 JavaFX 项目),将 JavaFX 库添加到上述模块路径中,现在您需要添加这些用于编译和运行的 VM 选项:

 --module-path=/path/to/javafx-sdk-11/lib --add-modules=javafx.controls

项目应该运行良好.

Maven

另一种方法是使用 Maven 或 Gradle 而不是 ant.

只需创建一个Maven -> JavaFX 项目,修改pom.xml 文件并添加JavaFX 依赖项:

<依赖><groupId>org.openjfx</groupId><artifactId>javafx-controls</artifactId><version>11-ea+23</version></依赖><依赖><groupId>org.openjfx</groupId><artifactId>javafx-fxml</artifactId><version>11-ea+23</version></依赖></依赖项><构建><插件><插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.7.0</version><配置><发布>11</发布></配置><依赖项><依赖><groupId>org.ow2.asm</groupId><artifactId>asm</artifactId><version>6.1.1</version><!-- 使用更新版本的 ASM --></依赖></依赖项></插件><插件><groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>1.2.1</version><执行><执行><目标><目标>java</目标></目标></执行></执行><配置><mainClass>javafx11.HelloFX</mainClass></配置></插件></插件></build>

从 NetBeans 清理、构建和运行,它应该可以正常工作.

对于 Gradle,如果您包含 NetBeans 的 Gradle 插件,也可以这样做.

I am migrating to OpenJDK 11 and OpenJFX 11. I have successfully built both from the source, and as per the OpenJFX wiki used the --with-import-modules=[path_to_modular_sdk] arg to build the JDK. everything goes well until I try to build a simple "Hello World" test project in Apache Netbeans 9; at this point I get the following error: "JavaFX deployment library not found in active JDK". Tried searching for info on this but could not find anything relevant. If anyone could shed light on what is causing this I would much appreciate it. Thanks for any help. Patrick.

解决方案

As @mipa points out, you don't need to build neither Java 11 nor JavaFX 11 in order to migrate your existing projects.

As for Apache NetBeans 9.0, the current ant build files for JavaFX project don't support JavaFX 11 yet. It is always looking for the JavaFX jar, and it will stop when it is not found. This is somehow legacy from the old days (before Java 8), when JavaFX was not part of the JDK and you had to add the jar manually.

For instance, when you try to create a new JavaFX project, you will get this error:

But this doesn't mean that you can't run JavaFX 11, with or without NetBeans 9.0.

Running on terminal

You can run your Java/JavaFX 11 project from a terminal. You can follow this getting started guide for a detailed step by step.

In a nutshell, all you need is:

export PATH_TO_FX=/path/to/javafx-sdk-11/lib
javac --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX.java
java --module-path $PATH_TO_FX --add-modules=javafx.controls HelloFX

where HelloFX.java is:

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 {

    @Override
    public void start(Stage stage) {
        String version = System.getProperty("java.version");
        Label l = new Label ("Hello, JavaFX 11, running on " + version);
        Scene scene = new Scene(new StackPane(l), 300, 200);
        stage.setScene(scene);
        stage.show();
    }

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

}

Modular Project

Create a modular project on NetBeans 9.0, and add a module (for the sake of simplicity I named it javafx11, which is not a recommended name).

Before adding the code, let's add the JavaFX library to the module-path.

This library is just the folder under my local download of JavaFX: /Users/<user>/Downloads/javafx-sdk-11/lib/. Of course, if you have built it yourself, you can point to that location instead.

Now I can define the module:

module javafx11 {
    requires javafx.controls;

    exports javafx11;
}

and add the above HelloFX class to the javafx11 package.

Now the project will run perfectly fine.

Even if you are still using ant, in this case, the build files are updated to the module-path changes, and there is nothing JavaFX specific, so the project runs without any issue.

Java project

If the modular project works, then a regular Java project will work as well on NetBeans 9.0.

Create a Java project (again, not a JavaFX project), add the JavaFX library to the module-path as above, and now you will need to add these VM options both for compiling and running:

 --module-path=/path/to/javafx-sdk-11/lib --add-modules=javafx.controls

The project should run fine.

Maven

Another approach is using Maven or Gradle instead of ant.

Just create a Maven -> JavaFX project, modify the pom.xml file and add the JavaFX dependencies:

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11-ea+23</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11-ea+23</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <release>11</release>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm</artifactId>
                    <version>6.1.1</version>
                    <!--  Use newer version of ASM  -->
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>javafx11.HelloFX</mainClass>
                </configuration>
        </plugin>
    </plugins>
</build>

Clean, build and run from NetBeans, it should work just fine.

For Gradle, the same can be done, if you include the Gradle plugin for NetBeans.

这篇关于在活动 JDK 中找不到 JavaFX 部署库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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