From a17de2fd2855df4de9f82b1de65f09d10a4b3a9d Mon Sep 17 00:00:00 2001 From: James Date: Sat, 27 Apr 2019 00:03:31 +0100 Subject: [PATCH] Enable cross-OS compatible fat-jar builds with Gradle's shadowDist tasks. --- build.gradle | 12 +++++++++++- src/main/kotlin/org/idiosapps/Main.kt | 14 ++++++++++++++ src/main/kotlin/org/idiosapps/MainApp.kt | 7 +++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/org/idiosapps/Main.kt diff --git a/build.gradle b/build.gradle index 3e3403a..fd2a2df 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,13 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.15' compile group: 'com.jfoenix', name: 'jfoenix', version: '9.0.8' + + // cross-platform jar: https://github.com/openjfx/samples/blob/master/CommandLine/Non-modular/Gradle/hellofx/build.gradle + // enable these when doing Gradle's shadowDistZip + // for cross-OS compatibility + compile "org.openjfx:javafx-graphics:12.0.1:win" + compile "org.openjfx:javafx-graphics:12.0.1:linux" + compile "org.openjfx:javafx-graphics:12.0.1:mac" } compileKotlin { @@ -31,4 +38,7 @@ javafx { modules = [ 'javafx.controls', 'javafx.fxml' ] } -mainClassName = 'org.idiosapps.MainApp' \ No newline at end of file +application { + mainClassName = 'org.idiosapps.Main' + applicationName = 'gradedReaderBuilder' +} \ No newline at end of file diff --git a/src/main/kotlin/org/idiosapps/Main.kt b/src/main/kotlin/org/idiosapps/Main.kt new file mode 100644 index 0000000..b340fba --- /dev/null +++ b/src/main/kotlin/org/idiosapps/Main.kt @@ -0,0 +1,14 @@ +package org.idiosapps + +// https://stackoverflow.com/a/34833438/4261132 +// To make a fat jar with JavaFX, +// we can't have the MainClass extend Application +// So, unfortunately we have to hack 2 static methods to get to the app! +class Main { + companion object{ + @JvmStatic + fun main(args: Array) { + MainApp.main(args) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/idiosapps/MainApp.kt b/src/main/kotlin/org/idiosapps/MainApp.kt index bd129d7..5a095e7 100644 --- a/src/main/kotlin/org/idiosapps/MainApp.kt +++ b/src/main/kotlin/org/idiosapps/MainApp.kt @@ -20,4 +20,11 @@ class MainApp : Application() { stage.scene = scene stage.show() } + + companion object{ + @JvmStatic + fun main(args: Array) { + launch(MainApp::class.java) + } + } } \ No newline at end of file