1

I'd like to build my Gluon Project as a SINGLE executable jar file.

Currently there is a startup script included with a bin folder and so on.

Is it possible to build a single jar? Or can I include an own gradle task that accomplishes this?

LucaZ
  • 87
  • 8

2 Answers2

0

The current tasks like installApp or distZip will not bundle the jars in one.

If you want to create a 'fat-jar', you can add this plugin to your build.gradle script:

buildscript {
    repositories {
        jcenter()

    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.8'
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
    }
}

apply plugin: 'org.javafxports.jfxmobile'
apply plugin: 'com.github.johnrengelman.shadow'

And then run gradlew shadowJar. It will create under libs an executable jar.

Note: if you are using desktopCompile or desktopRuntime dependencies, those won't be included so you need to change those to compile or runtime.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • Thank you for your Answer, I fixed it myself. I had Problems building it like a normal jar because of Javafx. But now works :D – LucaZ Apr 07 '16 at 08:26
0

Since I had to build the jar with javapackager I used this plugin: javafx-gradle-plugin

I am relatively new to Gradle so adding the dependencies is just a temporary solution but it works

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.8'
        classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.4.1'
    }
}

jfx {
    verbose = true
    mainClass = "package.path.to.main.class.MainClass"
    jfxAppOutputDir = "build/jfx/app" //configurable
    jfxMainAppJarName = "ProjectName.jar"
    deployDir = "src/main/deploy" //for signing

    //many more options, go to link to learn about them
}


jfxJar.doFirst {
    //TODO add all desktop dependencies
    println("adding desktop dependency")
    project.dependencies.add("runtime", "com.gluonhq:charm-desktop:2.1.0")
}
LucaZ
  • 87
  • 8