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

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

问题描述

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

解决方案

正如@mipa指出的那样,你既不需要构建Java 11也不需要构建JavaFX 11为了迁移现有项目。



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



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



< a href =https://i.stack.imgur.com/z67Sd.png =noreferrer>



但这并不意味着无论是否使用NetBeans 9.0都无法运行JavaFX 11.



在终端上运行



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



这个库只是我本地下载JavaFX的文件夹: /用户/<使用者> /下载/ JavaFX的SDK-11 / LIB / 。当然,如果你自己构建它,你可以指向那个位置。



现在我可以定义模块:

 模块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>
< / 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>
<依赖>
< groupId> org.ow2.asm< / groupId>
< artifactId> asm< / artifactId>
< version> 6.1.1< / version>
<! - 使用更新版本的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>

从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天全站免登陆