Search code examples
gradleexedebopenjfxopenjdk-11

How to build(gradle) .deb and .exe from java application developed with openJavaFx 11


I'm developing a javafx application using,

  • gradle
  • OpenJdk11
  • OpenJfx11
  • sqlite (It also stored inside main package as sqlite.db)

Now I need to build .deb file for ubuntu installation and .exe file for window installation

build.gradle here

plugins {
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'application'
apply plugin: 'war'

    group = 'dmhashan'

mainClassName = 'dmhashan.payroll.AppStarter'

repositories {
    jcenter()
    mavenCentral()
    mavenLocal()
}

dependencies {
    testImplementation 'junit:junit:4.13'
    implementation 'org.openjfx:javafx:14-ea+2'
    implementation 'com.1stleg:jnativehook:2.0.2'
    implementation 'net.java.dev.jna:jna:5.5.0'
    implementation 'net.java.dev.jna:jna-platform:5.5.0'
    implementation 'com.j256.ormlite:ormlite-core:5.1'
    implementation 'com.j256.ormlite:ormlite-jdbc:5.1'
    implementation 'org.xerial:sqlite-jdbc:3.23.1'
    providedCompile 'com.konghq:unirest-java:3.7.02'
    implementation 'com.konghq:unirest-object-mappers-gson:3.7.02'
}

javafx {
    version = "11.0.2"
    modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.graphics' ]
}

run() {
    jvmArgs = ['--add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED']
}

Solution

  • With just Gradle you can only build an executable JAR that can run on Windows and Linux. To bundle it into an exe or a deb package, you'll need some Gradle plugins.

    For the exe, you can use gradle-launch4j.

    For the deb, you can sue gradle-ospackage-plugin. You find the documentation here.