您必须指定javafx控件的完整路径。我建议使用gradle或maven作为选择器。使用gradle,您可以创建一个bat文件,该文件将运行您的应用程序并负责其余的工作。
project structure
build.gradle
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.beryx.jlink' version '2.17.2'
}
javafx {
version = "11.0.2"
modules = [ 'javafx.controls' ] // you can add 'javafx.fxml',...
}
group 'flpe'
version '1.0-SNAPSHOT'
// Use Java 13 only if you use Gradle 6+
// The JDK folder must be added to the environment variable JAVA_HOME
(https://www.wikihow.com/Set-Java-Home)
sourceCompatibility = 1.11
repositories {
mavenCentral()
}
jlink {
launcher {
name = 'exe_name'
}
}
mainClassName = 'javafx.jlink.example.main/gui.Main'
必定要
modul-info.java !
module javafx.jlink.example.main {
requires javafx.controls;
exports gui;
}
Main.java
package gui;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main 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("Useless button");
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root,300,250));
primaryStage.show();
}
}
本文链接:https://www.f2er.com/1757067.html