[英]Deploy JavaFX application using gradle 6.3, OpenJDK 14 and OpenJFX 14
我正在使用 gradle 6.3、OpenJDK 14 和 OpenJFX 14 和 IntelliJ 開發 JavaFX 應用程序,我想部署它(創建一個 exe 文件)。
我曾經在 Netbeans 11 下使用 JDK 8 制作 JavaFX 應用程序,過程很簡單:
由於我正在遷移到 OpenJDK 14,因此我想確保我可以部署我正在制作的應用程序,因此我創建了一個應用程序,並且在我運行它時一切正常(在 IntelliJ 中)。 我看到了一些關於如何使用 gradle 部署 javafx 應用程序的教程,我想到了這個過程:
我嘗試使用命令行運行它,這就是我得到的:
C:\Users\Admin\Documents\SmartDoc\build\distributions\SmartDoc-1.0\SmartDoc-1.0\lib>java -jar SmartDoc-1.0.jar
Table PATIENT created successfully !
Table DOSSIER_MEDICAL created successfully !
Table ORDONNANCE created successfully !
Table RENDEZ_VOUS created successfully !
Table SALLE_ATTENTE created successfully !
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: javafx.fxml.LoadException:
file:/C:/Users/Admin/Documents/SmartDoc/build/distributions/SmartDoc-1.0/SmartDoc-1.0/lib/SmartDoc-1.0.jar!/main.fxml:27
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2603)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
at com.smartdoc.gui.Launch.start(Launch.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:262)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)
at javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:520)
at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:370)
at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:332)
at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:242)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:775)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2838)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2557)
... 17 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at com.sun.javafx.fxml.ModuleHelper.invoke(ModuleHelper.java:100)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:258)
... 25 more
Caused by: java.lang.UnsupportedOperationException: Cannot resolve 'fa-user-plus'
at org.kordamp.ikonli.javafx.IkonResolver.resolveIkonHandler(IkonResolver.java:62)
at org.kordamp.ikonli.javafx.FontIcon.setIconLiteral(FontIcon.java:239)
... 31 more
前 5 行是應用程序創建 derby 數據庫的結果(運行良好),但在運行應用程序時出現了一些異常。 I also tried running with --module-path "C:\Program Files\Java\javafx-sdk-14.0.1\lib" --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.graphics
but我有同樣的例外。
有 3 個我不知道的解決方案:
編輯: build.gradle 文件:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
group 'com.smartdoc'
version '1.0'
repositories {
mavenCentral()
}
dependencies {
compile 'com.calendarfx:calendar:11.8.3'
compile 'com.calendarfx:view:11.8.3'
compile 'org.kordamp.ikonli:ikonli-core:11.4.0'
compile 'org.kordamp.ikonli:ikonli-javafx:11.4.0'
compile 'org.kordamp.ikonli:ikonli-fontawesome-pack:11.4.0'
compile 'com.jfoenix:jfoenix:9.0.9'
compile group: 'org.apache.derby', name: 'derby', version: '10.15.2.0'
compile group: 'org.apache.derby', name: 'derbyclient', version: '10.15.2.0'
compile group: 'org.apache.derby', name: 'derbynet', version: '10.15.2.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
javafx {
version = "14.0.1"
modules = ['javafx.controls','javafx.fxml']
}
mainClassName = "$moduleName/com.smartdoc.Main"
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
謝謝你的幫助!
所以我嘗試了一些解決方案來使我的.jar文件有效,我終於找到了一個:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
}
}
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
apply plugin : 'com.github.johnrengelman.shadow'
(如您所見,我使用了Gradle 影子插件)
我還在尋找如何制作它.exe,所以如果有人有建議,歡迎!
我終於設法從我之前創建的 jar 創建了一個.exe文件:我使用了 Launch4j (是的,它適用於 Java > 11)。 以下是簡單的步驟:
PS:您可以使用 Launch4j 添加圖標、清單文件和許多其他內容,我只是解釋了最簡單的示例,以便你們可以使其工作,rest 由您決定:)
如果有其他解決方案,請與我們分享,很多人都在為 JDK 14 的可執行文件而苦惱。
謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.