首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当VM选项设置为一个目录时,JavaFX程序不会运行,但是当设置为具有相同文件的另一个目录时,则运行良好。

当VM选项设置为一个目录时,JavaFX程序不会运行,但是当设置为具有相同文件的另一个目录时,则运行良好。
EN

Stack Overflow用户
提问于 2018-11-13 18:36:30
回答 1查看 1.7K关注 0票数 0

我在IntelliJ (Java11)中有一个包含两个模块的项目。一个是简单的java模块,另一个是JavaFX程序。这两个文件都是空的,因为我正在设置用于Git的项目结构,并试图消除任何绝对的文件路径。

项目的根目录是一个lib文件夹,它包含JavaFX的所有JAR(加上JUnit的其他一些)。这些文件是从我最初提取的JavaFX文件夹中直接复制到的(在构建非Git JavaFX项目时,我仍然很好地使用该文件夹)。

我将这些JAR作为依赖项添加到项目中。使用它们的任何代码都显示IDE中没有错误。我知道要让JavaFX项目运行,必须在运行配置中将--module-path <path to JavaFX libs> --add-modules=javafx.controls,javafx.fxml添加到VM选项中。这就是问题所在。

当我使用前面提到的JavaFX的原始提取位置的路径时,一切正常工作(即程序窗口打开):--module-path C:/Tools/JavaFX/lib/ --add-modules=javafx.controls,javafx.fxml

但是,当我使用项目中包含相同文件(加上JUnit文件)的lib文件夹的路径时,它不起作用(我得到运行时错误,程序没有显示其窗口):--module-path C:/Users/Henry/Documents/IntelliJ/LAA_Rotas_4/lib/ --add-modules=javafx.controls,javafx.fxml

以下是运行时输出:

代码语言:javascript
复制
"C:\Program Files\Java\jdk-11\bin\java.exe" --module-path C:/Users/Henry/Documents/IntelliJ/LAA_Rotas_4/lib/ --add-modules=javafx.controls,javafx.fxml "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.4\lib\idea_rt.jar=57474:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.2.4\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\out\production\Demo;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\apiguardian-api-1.0.0.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\javafx-swt.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\javafx.base.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\javafx.controls.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\javafx.fxml.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\javafx.graphics.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\javafx.media.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\javafx.swing.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\javafx.web.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\junit-jupiter-api-5.3.1.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\junit-platform-commons-1.3.1.jar;C:\Users\Henry\Documents\IntelliJ\LAA_Rotas_4\lib\opentest4j-1.1.1.jar net.atos.laa_rotas.demo.Main
Graphics Device initialization failed for :  d3d, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:280)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:222)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:260)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
    at java.base/java.lang.Thread.run(Thread.java:834)
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: No toolkit found
    at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    ... 5 more

Process finished with exit code 1

在内部,在用于workspace.xml的IntelliJ文件中,这些VM选项被转换为--module-path $PROJECT_DIR$/lib/ --add-modules=javafx.controls,javafx.fxml。但是,即使我在C:/Users/Henry/Documents/IntelliJ/LAA_Rotas_4/lib/文件中直接设置了workspace.xml路径并重新加载和运行项目,也没有什么变化。

有人知道为什么会发生这种情况吗?有什么可以解决的呢?

EN

回答 1

Stack Overflow用户

发布于 2021-04-25 15:05:33

我也遇到了同样的问题,但是我找到了解决这个问题的方法--您只需要在您的intelliJ VM选项中添加它,

右键单击主类,然后单击“修改运行配置”,然后在VMoptions中添加以下行,并确保替换目录

代码语言:javascript
复制
    --module-path
"C:\Users\your-directory\javafx-sdk-16\lib"
--add-modules
"javafx.controls,javafx.fxml"

并确保lib文件夹所在的目录中有javafx的所有文件和目录

bin

legal

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53287489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档