No main manifest attribute kotlin gradle

Ошибка программы kotlin: в файле jar отсутствует основной атрибут манифеста

Попробуйте обновить до версии 1.3.41 и использовать JDK 1.11+.

Я столкнулся с этим ответом, имея ту же проблему с Kotlin и Gradle. Я хотел упаковать, чтобы заставить банку работать, но продолжал пилинг ошибки.

С файлом типа com.example.helloworld.kt , содержащим ваш код:

Итак, вот как будет выглядеть файл build.gradle.kts , чтобы вы начали работать с Gradle.

import org.gradle.kotlin.dsl.* import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins < application kotlin("jvm") version "1.3.50" >// Notice the "Kt" in the end, meaning the main is not in the class application.mainClassName = "com.example.MainKt" dependencies < compile(kotlin("stdlib-jdk8")) >tasks.withType  < kotlinOptions.jvmTarget = "1.8" >tasks.withType  < // Otherwise you'll get a "No main manifest attribute" error manifest < attributes["Main-Class"] = "com.example.MainKt" >// To add all of the dependencies otherwise a "NoClassDefFoundError" error from(sourceSets.main.get().output) dependsOn(configurations.runtimeClasspath) from(< configurations.runtimeClasspath.get().filter < it.name.endsWith("jar") >.map < zipTree(it) >>) > 

Итак, когда вы gradle clean build вы можете сделать:

Предполагая, что ваш проектор использует банку в build/libs/hello.jar , предполагая, что в вашем settings.gradle.kts вы установили rootProject.name = «hello»

Читайте также:  Python get all functions in module

Тогда вы можете запустить:

java -jar hello.jar > Hello, World! 

Источник

‘»No main manifest attribute» when creating Kotlin jar using IntelliJ IDEA

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:

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.

Solution 1: [1]

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 for more details.

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

Solution 2: [2]

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

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

Solution 3: [3]

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

Solution 4: [4]

For Spring boot apps:

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

plugins < id("org.springframework.boot") version "2.6.7" >apply(plugin = "io.spring.dependency-management") 

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

gradle / kotlin-dsl-samples Public archive

No main manifest attribute in jar file #1314

No main manifest attribute in jar file #1314

Comments

I can’t generate jar for my kotlin application.
I have gradle dsl script

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins < application kotlin("jvm") version "1.3.11" > group = "DataCheck" version = "1.0-SNAPSHOT" application < mainClassName = "com.MainKt" > repositories < mavenCentral() >dependencies < compile(kotlin("stdlib-jdk8")) implementation(files("lib/SimpleExcelReader.jar")) > tasks.withTypeJar> < manifest < attributes["Main-Class"] = application.mainClassName > from(configurations.runtime.get().map if (it.isDirectory) it else zipTree(it)>) > tasks.withTypeKotlinCompile> < kotlinOptions.jvmTarget = "1.8" >

And structure of my project:

image

image

When I generate jar file, it does not contains correct MANIFEST.MF file:

image

but I expected something like this:

The text was updated successfully, but these errors were encountered:

Источник

Gradle — no main manifest attribute

Try to change your manifest attributes like:,Or why mainClassName does not specify the attribute in the manifest?,no main manifest attribute, in RxJavaDemo.jar,To make the jar file executable (so that the java -jar command works), specify the Main-Class attribute in MANIFEST.MF.

Try to change your manifest attributes like:

jar < manifest < attributes( 'Class-Path': configurations.compile.collect < it.getName() >.join(' '), 'Main-Class': 'hello.HelloWorld' ) > > 

Answer by Zaylee Weber

Try to change your manifest attributes like:,Or why mainClassName does not specify the attribute in the manifest?,$ ./gradlew run will launch the main method in the class specified in the attribute,To make the jar file executable (so that the java -jar command works), specify the Main-Class attribute in MANIFEST.MF.

Try to change your manifest attributes like:

jar < manifest < attributes( 'Class-Path': configurations.compile.collect < it.getName() >.join(' '), 'Main-Class': 'hello.HelloWorld' ) > > 
  • for Groovy DSL see these answers ([1], [2])
  • for Kotlin DSL you can use the following code snippet:

Here is the line of shell script setting the main class:

$ grep Main2 gradletest eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLETEST_OPTS -classpath "\"$CLASSPATH\"" com.caco3.gradletest.Main2 "$APP_ARGS" 

Answer by Augustus Beltran

You might get this error when Main-Class entry is missing in MANIFEST.MF file. You can put maven-jar-plugin plugin in pom.xml to fix it.,When you have a self-executable jar and trying to execute it. You might get this error.,Once you run the above-mentioned solution and reopen MANIFEST.MF file in jar again, you will see Main-Class entry.,In case, you are getting an error while running spring boot application, you can solve it with spring-boot-maven-plugin.

Maven

You might get this error when Main-Class entry is missing in MANIFEST.MF file. You can put maven-jar-plugin plugin in pom.xml to fix it.

Maven

You might get this error when Main-Class entry is missing in MANIFEST.MF file. You can put maven-jar-plugin plugin in pom.xml to fix it.

Maven

You might get this error when Main-Class entry is missing in MANIFEST.MF file. You can put maven-jar-plugin plugin in pom.xml to fix it.

Answer by Zaid Owen

How do I set the main class?,Gradle has changed a bit. To get latest had to find SDKMAN! and then spent a bit of time figuring out how to use gradle init to create the wrapper so that it plays nicely with Netbeans. Hence, admittedly, wasn’t able to research how to set the main class correctly; pardon.

How do I set the main class?

[email protected]:~/NetBeansProjects/Firebase$ [email protected]:~/NetBeansProjects/Firebase$ ./gradlew build --scan BUILD SUCCESSFUL in 10s 2 actionable tasks: 2 executed Publishing build scan. https://gradle.com/s/gwb6wfhdghyfi [email protected]:~/NetBeansProjects/Firebase$ [email protected]:~/NetBeansProjects/Firebase$ java -jar build/libs/Firebase.jar no main manifest attribute, in build/libs/Firebase.jar [email protected]:~/NetBeansProjects/Firebase$ [email protected]:~/NetBeansProjects/Firebase$ cat build.gradle plugins < id 'com.gradle.build-scan' version '1.8' id 'java' >buildScan < licenseAgreementUrl = 'https://gradle.com/terms-of-service' licenseAgree = 'yes' >repositories < jcenter() >dependencies < compile 'org.slf4j:slf4j-api:1.7.24' testCompile 'junit:junit:4.12' >[email protected]:~/NetBeansProjects/Firebase$ 

Answer by Armani Whitehead

no main manifest attribute, in «app.jar»,7007/unable-to-execute-jar-file-no-main-manifest-attribute,I had the manifest file in correct place, containing the Main-Class and everything. What tripped me over was this:, Unable to execute jar- file no main manifest.

If it’s not an executable JAR, then you’ll need to run the program with something like:

java -cp app.jar com.somepackage.SomeClass

Answer by Jakari Carrillo

The «no main manifest attribute» error message may occur in a Maven project due to the absence of the Main-Class entry in MANIFEST.MF.,The Main, or Main-Class is an essential attribute to make your jar executable. It tells Java which class would be used as the entry point of the application.,»no main manifest attribute» error message is thrown because of various reasons, but most of the time, it fall under one of the following category.,In this article, we will show you a few possible fix that you can apply to your Java project to avoid getting «no main manifest attribute» error.

«no main manifest attribute» is a common error which happens when we try to run an executable jar file. The full error output may look like what’s shown below

Unable to execute jar- file: "no main manifest attribute." 
no main manifest attribute, in target/exec.jar

A typical MANIFEST.MF file should contain the following lines

Manifest-Version: the version of the Manifest file. Built-By: your PC name. Build-Jdk: the JDK version installed in your machine. Created-By: the plugin name used in IDE.

This issue can be resolved by adding maven-jar-plugin to our pom.xml file.

    org.apache.maven.plugins maven-jar-plugin 3.1.0   com.linuxpip.AppMain       

The following entries can be put into your build.gradle file if you receive this error in your Gradle project:

Answer by Amelia Reeves

May 7, 2021May 7, 2021,Likewise, if you’re using Gradle, then use this:,no main manifest attribute, in /src/project/target/your-jar-1.0-SNAPSHOT.jar,Then you can run it like this:

You need to create a META-INF/MANIFEST.MF file with the following content:

.wp-block-code.wp-block-code>div.shcb-language.hljs.hljs.shcb-code-table.hljs.shcb-code-table>.shcb-loc.hljs.shcb-code-table .shcb-loc>span.wp-block-code code.hljs:not(.shcb-wrap-lines).wp-block-code code.hljs.shcb-wrap-lines.hljs.shcb-line-numbers.hljs.shcb-line-numbers>.shcb-loc.hljs.shcb-line-numbers .shcb-loc>span.hljs.shcb-line-numbers .shcb-loc::beforeMain-Class: com.mypackage.MyClassCode language: CSS (css)

If using Maven, then you will need to add this to your POM.xml:

    org.apache.maven.plugins maven-jar-plugin 3.1.0   true lib/ com.mypackage.MyClass       Code language: HTML, XML (xml)
plugins < id 'java' >jar < manifest < attributes ( 'Main-Class': 'com.mypackage.MyClass' ) >> Code language: Groovy (groovy)
java -cp app.jar com.mypackage.MyClass Code language: CSS (css)

If all else has failed, then you can always use this Maven goal to get the job done:

 maven-assembly-plugin  package single      true com.mypackage.MyClass   jar-with-dependencies    Code language: HTML, XML (xml)

Answer by Legacy Bailey

clairegallup ,It appears that the main class isn’t specified in the .jar file because jar.manifest.Class-Path isn’t set in build.gradle (source).,Successfully merging a pull request may close this issue.,I am currently working on documentation, and while trying to compile from the command line, the generated .jar file fails to run:

. \mentorbot>java -jar build\libs\mentorbot-1.0-SNAPSHOT.jar no main manifest attribute, in build\libs\mentorbot-1.0-SNAPSHOT.jar

Источник

Оцените статью