英文:
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.
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论