java - 使用 IntelliJ、OpenJFX 和 Gradle 构建 JAR 文件
问题描述
在 2021 年,使用 OpenJFX 在 IntelliJ 中使用 Gradle 创建可执行 jar 文件的最佳方法是什么?我发现的每个解决方案都非常复杂,并且使用了变通方法。这是我当前的 build.gradle 文件
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
repositories {
mavenCentral()
}
javafx {
version = "15.0.1"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
mainClassName = 'com.company.crawl.main.Main'
group 'com.company'
version '1.0-SNAPSHOT'
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '9.2.0.jre15'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.8'
}
jar {
from configurations.compile.collect {zipTree it}
manifest.attributes "Main-Class": "com.company.crawl.main.Main"
}
如果我运行 gradle :jar,jar 文件包含依赖项,但不包含 openjfx sdk。使用 openjfx sdk 运行 jar 需要做什么?
更新 1
将jar路径更改为:
jar {
manifest {
attributes 'Main-Class': 'com.company.crawl.main.Main'
}
from {
configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it)}
}
}
重建 jar 后,出现错误:“JavaFX 运行时组件丢失”。我不知道为什么,因为在 jar 文件中包含 javafx 文件夹。之后,我添加了 VM 选项:
--module-path /path/to/javafx-sdk/lib --add-modules=javafx.controls,javafx.fxml
jar 文件运行。那么我做错了什么?
解决方案
推荐阅读
- swift - SCNCamera.exposureOffset 在 iOS13 中不起作用
- android - 无法在 appium 中使用 Content-desc 单击按钮
- reactjs - 在单个博文模板中显示作者
- python-3.x - 来自 pandas_datareader 的连接数据
- performance - ReactNative 导航 - 寻找动态加载许多屏幕的最佳方式?
- apache - 将 .htacess 转换为 nginx 配置
- machine-learning - 逻辑回归无法找到 theta 的值
- javascript - 设置取决于另一个下拉列表的选择选项值?
- php - Php throw exception Fatal error Uncaught Exception in Visual Studio Code with XDebug
- python - 在 Django 中覆盖保存模型