I have problem assembling Kotlin project with some dependencies to JAR file using Maven.
How am i assembling project to JAR:
RightPanel -> MavenProjects -> Lifecycle -> package -> run
When i running JAR file:
java -jar path.jar
I'm getting following error:
no main manifest attribute, in path.jar
I've added maven-assembly-plugin
like here:
So my plugins directory looks like this:
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals> <goal>single</goal> </goals>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
main.class
property defined here:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.1.51</kotlin.version>
<junit.version>4.12</junit.version>
<main.class>ru.icarumbas.main.HelloKt</main.class>
</properties>
Some facts:
Hello.kt
is starter class and it has fun main(...){}
Versions:
Maybe i'm missing something. I've already looked on a lot of questions alike this, and they didn't help me. So please don't mark this as duplicate and write a comment if you want to see more code. I didn't show my full pom.xml
file so write me if you want to see it full.
I've got such problems with kotlin and maven. I've solved it in following way (Application.kt):
package org.somepackage
open class Application {
companion object {
@JvmStatic fun main(args: Array<String>) {
// something..
}
}
}
-- So first i've written the kotlin class with main inside it.
Secondly as in your case defined the main class in props in a following way <main.class>org.somepackage.Application</main.class>
After mvn clean install command finished i've got the necessary someapp-1.0-SNAPSHOT-jar-with-dependencies.jar which was able to work.
And at the end please pay attention that you run exactly jar-with-dependencies.jar (not a stripped version like a app-1.0-SNAPSHOT.jar).
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