英文:
OpenJDK8 and JavaFX on MacOS
问题
我想在 macOS 上运行一个仅适用于 OpenJDK 8 的 JavaFX 应用程序:
- 我在互联网上搜索,只找到适用于 Linux(使用 apt-get)的解决方案,
- 我无法升级到 OpenJDK > 8,也不能切换到 Oracle 发行版(上下文限制)。
编辑
问题在于,如果我使用 Oracle JDK 8 运行应用程序,它可以正常工作。但是,如果我使用 OpenJDK 8 运行它,包含 JavaFX 时就会出现问题。例如:
FilterEditor.java:6: 错误:找不到 javafx.scene.input 包
import javafx.scene.input.KeyEvent;
我正在使用 Gradle 脚本
jar {
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
apply plugin: 'org.openjfx.javafxplugin'
javafx {
version = "11"
modules = ['javafx.controls', 'javafx.fxml', 'javafx.swing']
}
} else if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
throw new GradleException("This build script must be run with java 8 or a java version >= 11")
}
destinationDir = projectDir
manifest.attributes 'Main-Class': project.mainClassName
baseName = 'XXX'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
但如果我使用 OpenJDK 8,就会失败。
英文:
I would like to run a JavaFX application on macOS that has only OpenJDK8:
- I searched on the internet and I only found solutions for Linux (with apt-get),
- I cannot upgrade to OpenJDK>8 and I cannot switch to Oracle distributions (context constraints).
** Edit **
The problem is that if I run the application with OracleSDK8 it works perfectly fine. But if I run it with OpenJDK8 I have problems when including JavaFX. For example:
FilterEditor.java:6: error: package javafx.scene.input does not exist
import javafx.scene.input.KeyEvent;
I'm using a Gradle script
jar {
if(JavaVersion.current() >= JavaVersion.VERSION_11){
apply plugin: 'org.openjfx.javafxplugin'
javafx {
version = "11"
modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.swing' ]
}
}else if(JavaVersion.current() != JavaVersion.VERSION_1_8){
throw new GradleException("This build script must be run with java 8 or a java version >= 11")
}
destinationDir = projectDir
manifest.attributes 'Main-Class': project.mainClassName
baseName = 'XXX'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
But if fails if I use OpenJDK8.
答案1
得分: 1
有几家提供OpenJDK + JavaFX的供应商。例如,您可以从Azul下载:https://www.azul.com/downloads/zulu-community/?version=java-8-lts&os=macos&architecture=x86-64-bit&package=jdk-fx
不过,您应该尝试升级到更近版本的Java/FX。
英文:
There are several providers of OpenJDK + JavaFX. E.g. you can download that from Azul: https://www.azul.com/downloads/zulu-community/?version=java-8-lts&os=macos&architecture=x86-64-bit&package=jdk-fx
Nevertheless you should try to upgrade to a more recent version of Java/FX.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论