Building fat jar? Specify main class?

Issue #34 resolved
Clayton Wohl
created an issue

How do I build a fat Jar?

With non-JavaFX projects I would do:

task fatJar(type: Jar) {
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

I get an error when I simply replace jar with jfxJar.

Also, how do I specify the main class? It seems to auto-guess the right one, but I'd like to configure if possible.

Comments (2)

  1. William Daniels

    If all you need to do is create a jar that has all of your downloaded dependencies in a single output jar, there are two things to do:

    1) jfxCopyLibs.enabled = false; and 2) you need to edit the regular 'jar' task as following:

    jar{
        configurations.compile.collect { it.isDirectory() ? it: zipTree(it)}
        from(configurations.compile) { 
        }
        manifest{
            attributes("Main-Class": mainClassName);
        }
    }
    

    That will make everything into a single jar. Tested with Java 1.7_60 64-bit

    Hope that helps!

  2. Danno Ferrin repo owner

    Use @William Daniels snippet for the fat jar. The javafxplugin will only be supporting that the javafxpackager does, it won't be a one stop shop.

    To specify the main class, you can add it in the javafx block:

    javafx {
      mainClass = 'your.application.Main'
    }
    

    But if you are already building a jar with a main-class manifest attribute it will sniff it out and use that.

  3. Log in to comment