Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin + Maven assembling: no main manifest attribute

Tags:

maven

jar

kotlin

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(...){}
  • When i unarchive JAR it has META-INF folder.

Versions:

  • Platform: Mac OS
  • Kotlin version: 1.1.51
  • Maven version: 4.0.0

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.

like image 625
icarumbas Avatar asked Oct 12 '25 07:10

icarumbas


1 Answers

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).

like image 113
Boris Davidov Avatar answered Oct 16 '25 11:10

Boris Davidov