Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 438 Vote(s) - 3.61 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"No main manifest attribute" when creating Kotlin jar using IntelliJ IDEA

#1
When creating a jar from my Kotlin code and running it, it says "No main manifest attribute".
When looking at the manifest.mf, it has this content:

Manifest-Version: 1.0

When looking at the file in the source, it has this content:

Manifest-Version: 1.0
Main-Class: MyMainClass

When manually copying the source manifest to the jar, it runs perfectly.

[Screenshot of my artifact settings][1]



[1]:
Reply

#2
If any of the dependent jars has a `MANIFEST.MF` file, it will override your custom one which defines the `Main-Class`.

In order to address this problem you should do the following:

- Disable the [alphabetical ordering](
)
- [Change items ordering](
) so that item which has `META-INF/MANIFEST.MF` file is the first in the list
- Your custom `MANIFEST.MF` will be picked up by IntelliJ IDEA and [displayed for the jar](
) artifact.

See the [related issue](

[To see links please register here]

) for more details.

You can also use Gradle or Maven to generate the fat jar instead.
Reply

#3
I got this error with Gradle and Kotlin.
I had to add in my `build.gradle.kts` an explicit manifest attribute:

```
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "com.example.MainKt"
}
}
```

From the [gradle documentation][1], it's better to create a fatJar task to englobe all of the runtime dependencies in case you encounter `java.lang.NoClassDefFoundError` errors

[1]:

[To see links please register here]

Reply

#4
1.Add the following task definition in the build script

tasks.jar {
manifest {
attributes["Main-Class"] = "MainKt"
}
configurations["compileClasspath"].forEach { file: File ->
from(zipTree(file.absoluteFile))
}
}

2. Then the jar tasks (Tasks | build | jar) again from the right hand sidebar.
Reply

#5
**For Spring boot apps:**

What worked for me (gradle kotlin) in build.gradle.kts

1) add spring boots plugin &. apply dependency management

```
plugins {
id("org.springframework.boot") version "2.6.7"
}
apply(plugin = "io.spring.dependency-management")
```

2) set your main class
```
springBoot {
mainClass.set("com.example.Application")
}
```

Found this all by reading up on spring-boot docs found [here](

[To see links please register here]

)
Reply

#6
So far the simplest and best solution I've found is using [Ktor Gradle Plugin][1]

plugins {
id("io.ktor.plugin") version "2.2.3" // Check if it's latest
}

application {
mainClass.set("com.example.ApplicationKt")
}

ktor {
fatJar {
archiveFileName.set("fat.jar")
}
}

Run it with ./gradlew buildFatJar


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through