简体   繁体   English

在 Mac 上安装 JavaFX 15

[英]Installing JavaFX 15 on Mac

I'm trying to install JavaFX 15 on my Mac but I'm stuck.我正在尝试在我的 Mac 上安装 JavaFX 15 但我被卡住了。

Running MacOS Mojave 10.14.6运行 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'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/.../ Mac 终端中的 javafx-sdk-15/lib"。

I'm using IntelliJ for programming and I tried to set the path at Project Structure - Libraries我正在使用 IntelliJ 进行编程,并尝试在 Project Structure - Libraries 中设置路径

but apps won't compile.但应用程序不会编译。

Could somebody help me?有人可以帮我吗? Thanks a lot in advance!提前非常感谢!

the second command that DomQ posted was incorrect: DomQ 发布的第二个命令不正确:

brew tap bell-sw/liberica

brew install --cask liberica-jdk15-full

You need to take care with environment variables mixing with GUI applications on macOS.您需要注意与 macOS 上的 GUI 应用程序混合的环境变量。 Setting PATH_TO_FX in the terminal likely didn't set the value for the IntelliJ IDE.在终端中设置 PATH_TO_FX 可能没有设置 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.您会注意到https://openjfx.io/openjfx-docs/#IDE-Intellij中的说明明确提到在 IDE 中设置该值,而不是从终端。

I strongly suggest using Gradle or Maven with the code samples given at https://OpenJFX.io/ as a starting point.我强烈建议使用 Gradle 或 Maven 以及https://OpenJFX.io/中给出的代码示例作为起点。 Confirm that the builds work from the command line before debugging what the IDE might be doing differently.在调试 IDE 可能会做不同的事情之前,请确认构建从命令行工作。

You can also install a JDK that includes the JavaFX modules.您还可以安装包含 JavaFX 模块的 JDK。 A few OpenJDK providers have such builds.一些 OpenJDK 提供商有这样的构建。 For example:例如:

My experience is that homebrew-liberica just works:我的经验是homebrew-liberica可以正常工作:

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

You can either use the terminal or set up a launch configuration in VS Code.您可以使用终端或在 VS Code 中设置启动配置。

To use the terminal, you can either install Liberica or download the latest JavaFX from Gluon (or the Early-Access build ).要使用终端,您可以安装Liberica或从 Gluon(或Early-Access 版本)下载最新的 JavaFX 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.要编译*.java文件,请确保在 CLI 上为javac指定并设置--module-path-cp作为命令 arguments。

For example , if you downloaded the JavaFX SDK to your ~/Downloads directory (ie, you downloaded JavaFX 16 and extracted it in your ordinary Downloads folder), then you will run something like 例如,如果您下载 JavaFX SDK 到您的~/Downloads目录(即,您下载了 JavaFX 16 并在您的普通下载文件夹中运行它)

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在此处检查您需要为--add-modules参数指定哪些模块: JavaFX 15 的 API 文档

Here is a sample launch.json to enable debug launching in VS Code:这是一个示例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}"
        }
    ]
}

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:对于 JDK,我建议将Liberica与 Homebrew 一起使用,因为它很容易保持最新(耶,Homebrew。)并且 Liberica 负责路径和环境变量(包括 JavaFX),要安装在 shell 中:尝试:

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

Then, to update然后,要更新

brew update && brew cask upgrade

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM