使用Gradle 6.3,OpenJDK 14和OpenJFX 14部署JavaFX应用程序 [英] Deploy JavaFX application using gradle 6.3, OpenJDK 14 and OpenJFX 14

查看:125
本文介绍了使用Gradle 6.3,OpenJDK 14和OpenJFX 14部署JavaFX应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有IntelliJ的gradle 6.3,OpenJDK 14和OpenJFX 14开发JavaFX应用程序,我想部署它(创建exe文件).

I am developping a JavaFX application using gradle 6.3, OpenJDK 14 and OpenJFX 14 with IntelliJ and I want to deploy it (create a exe file).

我以前在Netbeans 11下使用JDK 8制作JavaFX应用程序,过程很简单:

I used to make JavaFX applications with JDK 8 under Netbeans 11 and the process was simple:

  1. 申请该应用
  2. 清理并构建
  3. 在dist文件夹中查找jar(单击该按钮即可正常工作)
  4. 使用Launch4j将其转换为exe
  5. Voilà!

由于我正在迁移到OpenJDK 14,因此我想确保可以部署自己正在开发的应用程序,因此我创建了一个应用程序,并且在运行它时一切正常(在IntelliJ中).我看到了一些有关如何使用gradle部署javafx应用程序的教程,我想到了这个过程:

Since I am migrating to OpenJDK 14, I wanted to make sure I can deploy the app I am making, so I created an application and everything works when I run it (in IntelliJ). I saw some tutorials on how to deploy a javafx app with gradle and I came up to this process:

  1. 在gradle窗口(在屏幕的右上角)上,单击发行版> distZip
  2. 在build \ distibutions中查找生成的ZIP文件并将其解压缩
  3. 您将找到一个 bin lib 文件夹:在 bin 文件夹中,我找到了项目的 .bat 文件,当单击该文件时,我的应用程序启动,并且一切正常.在 lib 文件夹中,我找到了我在项目中使用过的所有jar文件以及{project-name} .jar,当我单击它时,什么也没发生. /li>
  1. On the gradle window (on the top right of the screen), click on distribution > distZip
  2. Look for the generated ZIP file in build\distibutions and unzip it
  3. You will find a bin and lib folder: In the bin folder, I have found a .bat file of my project and when clicked on it, my app starts and everything works fine. In the lib folder, I have found all the jar files I used in my project plus my {project-name}.jar and when I click on it nothing happens.

我尝试使用命令行运行它,这是我得到的:

I tried to run it using the command line and here's what I got:

    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数据库(完美运行)的结果,但是在运行该应用程序时,我遇到了一些例外. 我也尝试使用--module-path "C:\Program Files\Java\javafx-sdk-14.0.1\lib" --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.graphics运行,但是出现了相同的异常.

The first 5 lines are the result of the application creating a derby database (works perfectly), but when it comes to running the app I got some exceptions. 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 I got the same exceptions.

我不知道有3种解决方案:

There is 3 solutions which I know none of them:

  1. 解决此例外情况
  2. 尝试将该 .bat 文件转换为 .exe 文件
  3. 新解决方案
  1. Solve this exceptions
  2. Try to convert that .bat file to .exe file
  3. A new solution

build.gradle文件:

build.gradle file:

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) }
    }
}

感谢您的帮助!

推荐答案

更新1:制作有效的.jar文件

因此,我尝试了一些解决方案以使我的 .jar 文件正常工作,最后我找到了THE ONE:

UPDATE 1: Making a working .jar file

So I tried some solutions to make my .jar file works, and I finally found THE ONE:

  1. 添加到您的 build.gradle 顶部:

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 Shadow Plugin )

(As you can see I used the Gradle Shadow Plugin)

  1. 在gradle窗口中(在intelliJ IDE的右上方),单击 distribution> shadowDistZip
  2. 转到 build \ distributions ,您会找到一个ZIP文件({projectName} -shadow- {version}),将其解压缩.
  3. 打开文件夹,您将找到 bin lib 文件夹,转到 lib 文件夹以获取jar.
  4. 您会在您的 .jar 中找到满意的作品,如您的期望一样.
  1. In the gradle window (top right of the intelliJ IDE), click distribution > shadowDistZip
  2. Go to build\distributions and you will find a ZIP file ({projectName}-shadow-{version}), unzip it.
  3. Open the folder and you will find bin and lib folders, go to lib folder for jar.
  4. You will find there your .jar that sould work like your expectations.

我仍在寻找如何制作.exe,因此,如果有人有建议,欢迎您!

I am still looking how to make it .exe, so if anyone has a suggestion, welcome!

我终于设法从以前创建的jar中创建了一个 .exe 文件:我使用了 Launch4j (是的,它适用于Java> 11).简单的步骤如下:

I have finally managed to create an .exe file from the jar I created previously: I have used Launch4j (yes, it works with Java > 11). Here's the simple steps:

  1. 首先下载 Launch4j 并进行安装(不要运行它,它不能工作)
  2. 转到Launch4j文件,您将看到一个 launch4j.jar 文件,运行该文件并选择 Basic 标签
  3. 选择保存输出的路径(确保最后写.exe)
  4. 选择 .jar 文件所在的路径
  1. Download Launch4j first and install it (DONT RUN IT, IT WONT WORK)
  2. Go to Launch4j files and you will see a launch4j.jar file, run it and select Basic Tab
  3. Select the path where to save the output (make sure you write .exe at the end)
  4. Select the path where your .jar file is

  1. 现在转到 JRE 选项卡,在Min JRE版本中,选择11.0.1以确保它仅以Java> 11开头,而在Max JRE版本中,请选择选择所需的最高Java版本(在我的情况下,最新版本为14.0.1

  1. 现在单击顶部的齿轮,然后将配置文件保存在您想要的任何位置,然后Voilà!您的.exe文件现在应该可以正常运行.

PS:您可以使用Launch4j添加图标,清单文件和许多其他内容,我只是解释了最简单的示例,以便你们可以使用它,其余的取决于您: )

P.S.: You can add an icon, manifest file and many other stuff with Launch4j, I just explained the simpliest example ever just so you guys can make it work, the rest is up to you :)

如果还有另一种解决方案,请与我们分享,很多人都在使用JDK 14的可执行文件.

If there is another solution, please share it with us, many people are suffering with JDK 14 with the executable files.

谢谢!

这篇关于使用Gradle 6.3,OpenJDK 14和OpenJFX 14部署JavaFX应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆