-2

So I've found myself in a rabbit hole... I recently started learning javaFX and have made some apps here and there, well I've now run into a problem on how do I actually build them into a jar?

I use gradle to setup my projects, and run it through gradles application run

basically this video right here: https://www.youtube.com/watch?v=nKIMGH0l3Wo

The same guy that made that video also made a video about how to package it (https://www.youtube.com/watch?v=dLH-HjiCtaI). Although this doesn't work because I used kotlin to program my apps, and it uses jlink.

I've looked up a bunch of tutorials and guides, but they all talk about using some sort of packager like jlink.

I found a tutorial that builds an artifact which includes the resource folder, which was the closest I found to working, although the application doesn't run (Error: JavaFX runtime components are missing, and are required to run this application).

So is there a way I can build a jar file? Or did I make a mistake using Kotlin?

Thanks!

BahKooJ
  • 1
  • 1

1 Answers1

0

Luckily I manager to find some work arounds, you can use gradle and kotlin, but your main class can't inherit from javafx.application.Application. Rather you have your main class call the main function of your main application class, that was a lot of mains, but essentially just this

class Main {

    companion object {

        @JvmStatic
        fun main(args: Array<String>) {
            MainApplication().main(args)
        }
    }

}

(The solution I found) https://stackoverflow.com/a/52631238/16655016

BahKooJ
  • 1
  • 1
  • Just to note: Kotlin doesn't require you to create an entire class in order to have a main method. You can have it as a top-level function (e.g. `fun main(args: Array) = MainApplication.main(args)`). But you'll have to change the name of your "main class" when executing the application. For instance, if you put that top-level function in a file named `Main.kt` then (assuming a package of `sample`) the main class is `sample.MainKt`. – Slaw Aug 13 '21 at 04:43