带有JavaFx 11和JDK 11的Netbeans 9.0 [英] Netbeans 9.0 with JavaFx 11 and JDK 11

查看:111
本文介绍了带有JavaFx 11和JDK 11的Netbeans 9.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在NetBeans 9上运行JavaFX 11 由于JDK 11不再具有JavaFX,因此我无法让NetBeans运行JavaFX项目,它说:"Failed to automatically set-up a JavaFX Platform."

I am trying to run JavaFX 11 on NetBeans 9 Since JDK 11 does not have JavaFX anymore I couldn't get NetBeans to run a JavaFX project, it says: "Failed to automatically set-up a JavaFX Platform."

然后,我从该网站 https://gluonhq.com/products/javafx/下载了javafx11 a>, 在学习了本教程之后,我通常可以通过终端来编译和运行JavaFX类. 我可以添加JavaFX的唯一方法是使用Maven,但即使它构建成功,我也无法运行该应用程序.

I then downloaded the javafx11 from this website https://gluonhq.com/products/javafx/, after following the tutorial I was able to compile and run a JavaFX class normally through terminal. The only way I could add JavaFX is by using Maven, but I can't run the application even that it was built successfully.

    Error: JavaFX runtime components are missing, and are required to run this application
 Command execution failed.

还有其他与NetBeans一起运行JavaFX 11的方法吗?还是Eclipse?

Is there any other way to run JavaFX 11 with NetBeans? or maybe Eclipse?

推荐答案

也许是一个较晚的答案,但是,可能有javafx 11 maven项目+ NetBeans 9.

Maybe a late answer, but, it is possible to have javafx 11 maven project + NetBeans 9.

  1. Maven不喜欢在主要方面扩展Application.您应该使用两个类:

Main.java:

Main.java:

public class Main {

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

MainApp.java:

MainApp.java:

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 MainApp extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello World!");
        String a;
        a = new String("test");
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @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();
    }
}

  1. 您的pom.xml应该如下所示:

  1. Your pom.xml should look like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>YOUR GROUP ID</groupId>
        <artifactId>YOUR ARTIFACT ID</artifactId>
        <version>YOUR VERSION</version>

        <dependencies>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-controls</artifactId>
                <version>11</version>
            </dependency>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-media</artifactId>
                <version>11</version>
            </dependency>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-graphics</artifactId>
                <version>11</version>
            </dependency>
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-fxml</artifactId>
                <version>11</version>
            </dependency>
        </dependencies>

        <build>

            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>11</source>
                        <target>11</target>

                        <fork>true</fork>
                        <executable>PATH TO javac binary i.e. /usr/local/java/jdk-11.0.1/bin/javac</executable>


                        <compilerArgs>
                            <arg>-verbose</arg>
                            <arg>-Xlint:unchecked</arg>
                        </compilerArgs>

                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </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>Main</mainClass>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>Main</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        <name>YOUR ARTIFACT ID</name>
    </project>

这将在netbeans中正常工作. 基本上,您需要做的是启动新的maven项目,完成项目设置后,只需替换pom.xml.

This will work in netbeans without any issues. Basically, what you need to do is start new maven project and after you finish setting project just replace pom.xml.

这样,您的代码将从IDE运行,并且可以正确编译,因此您可以使用java --jar从命令行运行它.另外,您将能够运行NB调试器.

This way your code will run from IDE, and will compile correctly so that you can run it from command line with java --jar. Also, you will be able to run NB debugger.

这篇关于带有JavaFx 11和JDK 11的Netbeans 9.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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