我使用Eclipse导出了一个可运行的JAR文件,但无法运行该应用程序。

huangapple go评论83阅读模式
英文:

I exported a runnable jar using eclipse of my javafx14 application but cannot run the application

问题

我有一个问题,我目前正在使用eclipse上的javafx14项目进行工作,项目几乎完成了。

所以我将应用程序导出为可运行的jar文件。但是当我尝试在控制台中输入以下命令来运行它时。

java --module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml -jar app.jar

或者

java -jar app.jar

或者任何其他方式。
它给了我以下错误消息:

在引导层初始化期间发生错误
java.lang.module.FindException: 未找到模块javafx.controls

或者这个:

错误:缺少JavaFX运行时组件,需要运行此应用程序

请帮忙。先行感谢。

英文:

I have a problem, I am currently working on a javafx14 project on eclipse, And the project is almost done.

So I exported the application as a runnable jar. But when I try to run it using console by typing.

java --module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml -jar app.jar

or

java -jar app.jar

or anything really.
It gives me the following

Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found

or this :

Error: JavaFX runtime components are missing, and are required to run this application

Please Help. And thanks in advance

答案1

得分: 1

You must specify the full path to javafx controls. I recommend using gradle or maven as a picker. Using gradle, you can create a bat file that will run your app and take care of the rest.

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'

module-info.java necessarily!

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();
    }
}
英文:

You must specify the full path to javafx controls. I recommend using gradle or maven as a picker. Using gradle, you can create a bat file that will run your app and take care of the rest.

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 necessarily!

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

答案2

得分: 0

我通过确保将jar文件放在与库文件夹相同的位置来解决了这个问题。

就像这样:

-Jar文件。

-文件夹:lib

因此,总结一下,只需确保jar文件与您的lib文件夹位于同一位置。

英文:

I resolved the problem by making sure to put the jar file in the same place as the library folder.

like this:

-Jar file.

-Folder: lib

So in summary just make sure the jar file is in the same place as your lib.

huangapple
  • 本文由 发表于 2020年8月13日 01:38:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/63381958.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定