I am attempting to start my Dropwizard Kotlin application. When running:
java -jar target/application-1.0.jar server environment.yml
I get the following error:
Error: Main method is not static in class, please define the main method as:
public static void main(String[] args)
Make sure that the main
method in your application class is defined inside of a companion object with @JvmStatic
:
class MyClass {
companion object {
@JvmStatic
fun main(args: Array<String>) {
Application().run(*args)
}
}
}
function main can be a top-level function (let's say in a file called foo.bar.MainApp.kt
):
fun main(args: Array<String>) {
Application().run(*args)
}
If building and packaging with gradle and the application plugin then configure that with:
application {
mainClassName = "foo.bar.MainAppKt"
}
In build.gradle:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.41'
id 'application'
}
mainClassName = 'Main'
In Main.kt:
class Main {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println("Hello World!")
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With