安装 JavaFX 15 在 Mac 上

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

Installing JavaFX 15 on Mac

问题

我正在尝试在我的 Mac 上安装 JavaFX 15,但卡住了。

运行 MacOS Mojave 10.14.6。

我已经安装了 Java 13 JDK 并设置了主目录,从 https://gluonhq.com/products/javafx/ 下载了 JavaFX SDK,我已经在 Mac 终端中运行了代码 "export PATH_TO_FX=/Users/.../javafx-sdk-15/lib"。

我正在使用 IntelliJ 进行编程,并尝试在项目结构 - 库 中设置路径,但应用程序无法编译。

有人可以帮帮我吗?非常感谢!

英文:

I'm trying to install JavaFX 15 on my Mac but I'm stuck.

Running MacOS Mojave 10.14.6

I've already installed Java 13 JDK and set the Home folder, downloaded the JavaFX SDK from https://gluonhq.com/products/javafx/ , I've already ran the code "export PATH_TO_FX=/Users/.../javafx-sdk-15/lib" in Mac terminal.

I'm using IntelliJ for programming and I tried to set the path at Project Structure - Libraries

but apps won't compile.

Could somebody help me? Thanks a lot in advance!

答案1

得分: 9

第二条由DomQ发布的命令是不正确的:

brew tap bell-sw/liberica
brew install --cask liberica-jdk15-full
英文:

the second command that DomQ posted was incorrect:

brew tap bell-sw/liberica

brew install --cask liberica-jdk15-full

答案2

得分: 3

我的经验是 homebrew-liberica 就是有效的:

brew tap bell-sw/liberica
brew install --cask liberica-jdk15-full
英文:

My experience is that homebrew-liberica just works:

brew tap bell-sw/liberica
brew install --cask liberica-jdk15-full

答案3

得分: 2

你可以使用终端或在VS Code中设置启动配置。

要使用终端,你可以安装Liberica,或者从Gluon下载最新的JavaFX(或早期访问版本)。要编译你的*.java文件,请确保在命令行中为javac指定并设置--module-path-cp作为命令参数。

例如,如果你将JavaFX SDK下载到了~/Downloads目录(即你下载了JavaFX 16并将其解压到普通的Downloads文件夹中),那么你将运行类似以下的命令:

javac --module-path "$(eval echo ~$USER)/Downloads/javafx-sdk-16/lib/*" -cp "$(eval echo ~$USER)/Downloads/javafx-sdk-16/lib/*" -d . JavaFXThing.java

然后,为了运行你的程序,你会使用:

java --module-path "$(eval echo ~$USER)/Downloads/javafx-sdk-16/lib"  --add-modules javafx.controls,javafx.fxml JavaFXThing 

在这里查看你需要为--add-modules参数指定哪些模块:JavaFX 15的API文档

以下是一个样例的launch.json,用于在VS Code中启用调试启动:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Launch JavaFX Class",
            "request": "launch",
            "vmArgs": "--module-path \"/Users/kevinmou/Downloads/javafx-sdk-16/lib\"  --add-modules javafx.controls,javafx.fxml",
            "mainClass": "${file}"
        }
    ]
}

对于JDK,我建议使用Liberica和Homebrew,因为这样可以很容易地保持更新(耶,Homebrew! 🍻),而且Liberica会处理路径和环境变量(包括JavaFX)。要安装,请在Shell中尝试:

brew tap bell-sw/liberica
brew cask install liberica-jdk15-full

然后,要更新:

brew update && brew cask upgrade
英文:

You can either use the terminal or set up a launch configuration in VS Code.

To use the terminal, you can either install Liberica or download the latest JavaFX from Gluon (or the Early-Access build). To compile your *.java file, make sure to specify and set the --module-path and the -cp as command arguments for javac on the CLI.

For example, if you downloaded the JavaFX SDK to your ~/Downloads directory (i.e., you downloaded JavaFX 16 and extracted it in your ordinary Downloads folder), then you will run something like

javac --module-path "$(eval echo ~$USER)/Downloads/javafx-sdk-16/lib/*" -cp "$(eval echo ~$USER)/Downloads/javafx-sdk-16/lib/*" -d . JavaFXThing.java

Then, in order to run your program, you'll use:

java --module-path "$(eval echo ~$USER)/Downloads/javafx-sdk-16/lib"  --add-modules javafx.controls,javafx.fxml JavaFXThing 

Check what modules you need to specify for the --add-modules parameter here: API documentation for JavaFX 15

Here is a sample launch.json to enable debug launching in VS Code:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Launch JavaFX Class",
            "request": "launch",
            "vmArgs": "--module-path \"/Users/kevinmou/Downloads/javafx-sdk-16/lib\"  --add-modules javafx.controls,javafx.fxml",
            "mainClass": "${file}"
        }
    ]
}

For JDK, I recommend using Liberica with Homebrew, since it is easy to keep up-to-date (yay, Homebrew! 🍻) and Liberica takes care of the paths and environment variables (including JavaFX). To install, in a shell, try:

brew tap bell-sw/liberica
brew cask install liberica-jdk15-full

Then, to update

brew update && brew cask upgrade

答案4

得分: 1

在 macOS 上,您需要小心处理环境变量与图形界面应用程序的混合。在终端中设置 PATH_TO_FX 可能不会为 IntelliJ IDE 设置该值。您会注意到 https://openjfx.io/openjfx-docs/#IDE-Intellij 上的说明明确提到应在 IDE 中设置该值,而不是从终端中设置。

我强烈建议您使用在 https://OpenJFX.io/ 上提供的代码示例,以 Gradle 或 Maven 作为起点。在调试 IDE 可能存在的差异之前,请确认命令行中的构建是否正常运行。

您还可以安装包含 JavaFX 模块的 JDK。一些 OpenJDK 提供商提供了这样的构建。例如:

英文:

You need to take care with environment variables mixing with GUI applications on macOS. Setting PATH_TO_FX in the terminal likely didn't set the value for the IntelliJ IDE. You will note that the instructions at https://openjfx.io/openjfx-docs/#IDE-Intellij explicitly mention setting that value within the IDE, not from the Terminal.

I strongly suggest using Gradle or Maven with the code samples given at https://OpenJFX.io/ as a starting point. Confirm that the builds work from the command line before debugging what the IDE might be doing differently.

You can also install a JDK that includes the JavaFX modules. A few OpenJDK providers have such builds. For example:

huangapple
  • 本文由 发表于 2020年4月6日 07:33:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/61050869.html
匿名

发表评论

匿名网友

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

确定