如何使用gradle-launch4j插件将gradle项目编译为exe

问题描述 投票:0回答:2

我已经使用 Gradle 创建了一个 JavaFX 应用程序,并希望将其及其所有依赖项以及 JRE 导出到 exe,最好的方法是什么?

我尝试使用 Gradle-launch4j 提供的快速入门,但 exe 没有启动,它确实在 IDE 中启动,当我从命令行运行时 我收到错误

JavaFX modules are needed to run the application

这是我的 build.gradle 脚本

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.5'
    id 'edu.sc.seis.launch4j' version '2.4.6'
}

group 'Starter Apps'
version '1.0-SNAPSHOT'

sourceCompatibility = 11
mainClassName = "$moduleName/controllers.Main"

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile (group: 'com.jfoenix', name: 'jfoenix', version: '9.0.8'){
        exclude group: 'org.openjfx'
    }
    compile ('de.jensd:fontawesomefx-controls:11.0'){
        exclude group: 'org.openjfx'
    }
    compile ('de.jensd:fontawesomefx:8.9'){
        exclude group: 'org.openjfx'
    }
    compile ('de.jensd:fontawesomefx-icons525:4.6.3'){
        exclude group: 'org.openjfx'
    }
    compile (group: 'com.sun.mail', name: 'javax.mail', version: '1.6.2'){
        exclude group: 'org.openjfx'
    }
}

//create a single Jar with all dependencies
task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',
                'Implementation-Version': version,
                'Main-Class': "controllers.Main"
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}


javafx {
    modules = [ 'javafx.controls', 'javafx.fxml' ]
    version = '11.0.+'
}

launch4j {
    headerType='console'
    outfile = "Burj2.exe"
    icon = "${projectDir}/src/main/resources/images/icon.ico"
    jar = '../libs/Master_Mode_System_Config-all-1.0-SNAPSHOT.jar'
}

这是我的 module-info.java

module Master_Mode_System_Config {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.mail;
    requires com.jfoenix;

    opens controllers to javafx.fxml;
    exports controllers;
}

应用程序在 IDE 上运行良好,我真的很困惑为什么这是一个问题。 任何帮助将不胜感激。

java gradle javafx launch4j
2个回答
0
投票

使用以下更改更新您的 build.gradle。由于它是一个JavaFx应用程序,因此它不能是控制台类型。它应该是我在下面更新的 gui 类型。您必须提供具有完整包名称的主类名称(具有 main 方法的类名称)。运行后,您将能够看到exe文件并且可以启动它。

launch4j {
    headerType="gui"
    mainClassName = <provide your main class name>
    outfile = "Burj2.exe"
    icon = "${projectDir}/src/main/resources/images/icon.ico"
    jar = '../libs/Master_Mode_System_Config-all-1.0-SNAPSHOT.jar'
}

0
投票

我如何解决错误:缺少 JavaFX 运行时组件,需要运行此应用程序

  1. 创建一个新类(例如

    Main
    ),该类不使用 main 方法扩展
    Application

  2. App.main
    调用
    Main.main
    (应用程序扩展应用程序)方法。

  3. 现在运行应用程序并调用

    Main.main

public class App extends Application {
    [...]
    public static void main(String [] args) {
        launch(args);
    }
    [...]
}
public class Main {
    public static void main(String [] args) {
        App.main(args);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.