VSCode中的JavaFX-11:错误:无法找到或加载主类Files \ Java \ javafx-sdk-11.0.2 \ lib [英] JavaFX-11 in VSCode: Error: Could not find or load main class Files\Java\javafx-sdk-11.0.2\lib
问题描述
我一直试图在Visual Studio Code中设置JavaFX-11.
I have been trying to set up JavaFX-11 in Visual Studio Code.
我发现了这篇帖子带有VSCode的JavaFX-11 ,其中介绍了如何执行此操作,并按照步骤操作.
I found this post JavaFX-11 with VSCode, which explained how to do so, and followed the steps.
但是,我需要通过在launch.json
文件中添加vmArgs
的条目来包括JavaFX SDK的模块路径:
However, I need to include the module-path to the JavaFX SDK by adding an entry for the vmArgs
in the launch.json
file:
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - Main",
"request": "launch",
"vmArgs": "--module-path C:\\Program Files\\Java\\javafx-sdk-11.0.2\\lib --add-modules javafx.controls,javafx.fxml",
"mainClass": "hellofx.Main",
"projectName": "hellofx"
}
]
}
是我到JavaFX SDK的本地路径.但是,当我尝试运行程序时,出现以下错误:
As you can see in the vmArgs
entry, is my local path to the JavaFX SDK. However, when I try to run the program I get the following error:
错误:找不到或加载主类 文件\ Java \ javafx-sdk-11.0.2 \ lib由以下原因引起: java.lang.ClassNotFoundException:Files \ Java \ javafx-sdk-11.0.2 \ lib
Error: Could not find or load main class Files\Java\javafx-sdk-11.0.2\lib Caused by: java.lang.ClassNotFoundException: Files\Java\javafx-sdk-11.0.2\lib
在过去的几个小时里,我试图弄清楚为什么它不起作用.我写的论点错了吗?我看到有.jmods
文件.我应该下载那些文件吗?还有其他方法可以指定模块路径吗?
For the past hours I have trying to figure out why it doesn't work. Am I writing the arguments wrong? I saw there are .jmods
files. Should I download those files? Is there any other way to specify the module path?
值得一提的是,我正在Windows 10中运行Visual Studio Code,因此我必须使用转义序列来使用反斜杠.
Is worth to mention that I am running Visual Studio Code in Windows 10, so I have to use escape sequence to use backslashes.
推荐答案
如您所发布的错误所示,您可以看到:
As you can see by the error you have posted:
错误:找不到或加载主类Files \ Java \ javafx-sdk-11.0.2 \ lib
Error: Could not find or load main class Files\Java\javafx-sdk-11.0.2\lib
很明显,问题与您在Program Files
中的空间有关.
it is clear that the issue is related to the space you have in Program Files
.
解决方案
作为一种可能的解决方案,您可以将JavaFX SDK移至路径中没有空格的文件夹,并相应地设置vmArgs,例如:
As a possible solution, you could move your JavaFX SDK to a folder without spaces in its path, and set your vmArgs accordingly, like:
"vmArgs": "--module-path C:\\Java\\javafx-sdk-11.0.2\\lib --add-modules javafx.controls,javafx.fxml",
虽然可行,但如果您仍然希望保留当前的方法,则必须找到一种方法来使用空格设置路径.
While that works, if you still want to keep your current approach, you have to find a way to set the path with spaces.
基于类似的问题,您会发现:
Based on a similar issue, you can find that:
包含空格的路径应用(转义的)双引号引起来
Paths containing spaces should be surrounded by (escaped) double quotes
因此,这将是您的解决方案:
So this will be the solution in your case:
"vmArgs": "--module-path \"C:\\Program Files\\Java\\javafx-sdk-11.0.2\\lib\" --add-modules javafx.controls,javafx.fxml",
请注意,这不适用于带有JavaFX jar的.classpath
文件中添加的path
,这将是这样的:
Note this doesn't apply to the path
added in the .classpath
file with the JavaFX jars, that will be like this:
<classpathentry kind="lib" path="C:\\Program Files\\Java\\javafx-sdk-11.0.2\\lib\\javafx.base.jar"/>
这篇关于VSCode中的JavaFX-11:错误:无法找到或加载主类Files \ Java \ javafx-sdk-11.0.2 \ lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!