简体   繁体   English

如何从启动器类启动 TornadoFX 应用程序

[英]How to start a TornadoFX app from a launcher class

It's well known that for a fatjar to run properly for more recent versions of javafx applications the main class that launches the application cannot inherit from the Application class. 众所周知,要使fatjar 为最新版本的javafx 应用程序正确运行,启动应用程序的主类不能从Application 类继承。 The easy work around is creating a launcher class that calls the main method of the main class.简单的解决方法是创建一个调用主类的 main 方法的启动器类。

I'm having trouble doing this with Kotlin and TornadoFX (pretty new to both).我在用 Kotlin 和 TornadoFX 做这件事时遇到了麻烦(这对两者都很新)。

My example app is minimal:我的示例应用程序是最小的:

class MyApp: App(MainView::class, Styles::class) 

The question is how can I start this class from another launcher class?问题是我如何从另一个启动器类开始这个类?

I think the simplest and possibly best way to do this is with a function as follows.我认为最简单也可能是最好的方法是使用如下函数。

If we make a Kotlin file Launcher.kt name is not important.如果我们制作一个 Kotlin 文件 Launcher.kt 名称并不重要。 Contents below以下内容

package my.app

class MyApp: App(MainView::class, Styles::class) 

// stand alone function
fun main(args: Array<String>) {
launch<MyApp>(args)
}

then the main class name would be mainClassName = 'my.app.MyAppKt'那么主类名将是mainClassName = 'my.app.MyAppKt'

now we have a main class declaration this is used in the jars manifest or we could use the shaddow plugin for creating fat jars as shown here Shadow JAR现在我们有一个主类声明,它在 jars 清单中使用,或者我们可以使用 shaddow 插件来创建胖 jar,如下所示Shadow JAR

Note the launch function here is from tornadofx.App.kt注意这里的启动函数来自 tornadofx.App.kt

What I've done is put the function:我所做的是把函数:

fun main(args: Array<String>) {
    launch<MyApp>(args)
}

In the same file, but outside of the App class.在同一个文件中,但在 App 类之外。 I then have my IDE and build tool (Maven in my case) point to this file.然后我让我的 IDE 和构建工具(在我的例子中是 Maven)指向这个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM