I’m building my first kotlin spring-boot app w/jpa and a few controllers. It works fine when running within Intellij ultimate, but I need a working self-contained jar. I’m hitting a roadblock here when trying to run the self-contained jar.
First, I added the plugin in my pom.xml exactly as instructed in the url below.
instructions I’m following: https://kotlinlang.org/docs/reference/using-maven.html
After running mvn install or mvn package. My resulting target/my-api-0.0.1-SNAPSHOT-jar-with-dependencies.jar is 68M
Within the .jar class files exist as expected
BOOT-INF/classes/com/myproject/
- MyApplication$init$1.class
- MyApplication.class
- MyApplicationKt.class
And in META-INF/MANIFEST.mf the main class matches what I set for main.class in my pom.xml
Here’s the error I get when running the jar
java -jar target/my-api-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Error: Could not find or load main class com.myproject.MyApplicationKt (or without Kt depending on how I set main.class in my pom)
Heres what I’ve tried so far to get this self-contained jar working:
-
in pom.xml tried both
<main.class>com.myproject.MyApplicationKt</main.class> &&<main.class>com.myproject.MyApplication</main.class>package com.myproject @SpringBootApplication class MyApplication : WebMvcConfigurerAdapter() { // snip ... } fun main(args: Array<String>) { SpringApplication.run(MyApplication::class.java, *args) }
-
in pom.xml (same as before) tried both
<main.class>com.myproject.MyApplicationKt</main.class> &&
<main.class>com.myproject.MyApplication</main.class>
but instead w/ a companion object inside MyApplication. i.e.
class MyApplication : WebMvcConfigurerAdapter() {
companion object {
@JvmStatic fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}
}
}
Lastly:
- kotlin: 1.1.4
- spring boot: 1.5.6.RELEASE
- maven: 3.3.9