0
votes

I am trying to export my project from Intellij to a jar. Whenever I try to double click the jar and start it, it gives me the error "Java Jar file could not be launched. Check the console for more information". The console then says "no main manifest attribute". I searched a bit and found, that my Manifest is not exported correctly. In Intellij it has Main-Class: MainFrame in the MANIFEST.MF.

I opened the jar with Unarchiver and the attribute was missing the manifest of the jar. The exported manifest contains:

Manifest-Version: 1.0
Bundle-Description: Servlet Specification API
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0
Bundle-SymbolicName: org.mortbay.jetty.servlet-api
Archiver-Version: Plexus Archiver
Built-By: janb
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Bnd-LastModified: 1229016831353
Bundle-ManifestVersion: 2
Bundle-DocURL: http://www.mortbay.com
Bundle-Vendor: Mort Bay Consulting
Tool: Bnd-0.0.238
Implementation-Vendor: JCP
Originally-Created-By: 1.5.0_13 (Sun Microsystems Inc.)
Export-Package: javax.servlet.http;uses:="javax.servlet";version="2.5"
 ,javax.servlet;version="2.5",javax.servlet.resources;version="2.5",ja
 vax.servlet.jsp.resources;version="2.5"
Bundle-Version: 2.5
Bundle-Name: Servlet Specification API
Ignore-Package: javax.servlet.http,javax.servlet,javax.servlet.resourc
 es,javax.servlet.jsp.resources
Created-By: 1.5.0_13 (Sun Microsystems Inc.)
Build-Jdk: 1.5.0_13
Specification-Version: 2.5

Whilst my manifest in Intellij contains:

Manifest-Version: 1.0
Main-Class: MainFrame

I use gradle with

group 'tasks'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'application'

mainClassName = 'MainFrame'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'

jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
                'Implementation-Version': version,
                'Main-Class': 'MainFrame'
    }
}

I already tried moving the META-INF to resources and Clean and Rebuild the artifact, which was suggested in Creating Jar with Intellij 2016 - No main manifest attribute. I also know about the Intellij specific issue where it cannot find the manifest, if it is not moved to the resources folder..

I also watched several Youtube Videos but none seemed to fixed it.

Why is the mainclass-Attribute not properly embedded in the Manifest from the jar and how can I fix it?

1
This question migt help (not sure it is a duplicate though).Turing85
This does not seem like a manifest of your project. It is manifest of servlet api jar. Where is your manifest? And do you have class named "MainFrame" in your jar without any package name?gagan singh
@Turing85 I read that and I have added the solution to my problem. However, the proposed solution does not seem to help in my case..Basti
@gagansingh I think it is the manifest of my project. I read on various articles how to find the main project manifest and found the one in my description. I have a class MainFrame, yes, it does not contain a package ..; though which I will try to add and see if it helps!Basti
I tried to add a package ..; to the MainFrame class but it didn't work since gradle seemed to manage the packages.Basti

1 Answers

0
votes

I had the same problem and I am coding with IntelliJ. On my gradle I write the code below

    buildscript {
    ext {
        springBootVersion = '2.1.6.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


bootJar {
    baseName = 'yournameforyourjar'
    version =  '0.1.0'
}

jar {
    manifest {
        attributes(
                'Main-Class': 'yourpackagename.Application'
        )
    }
}


repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {

    compile group: 'org.springframework.boot', name: 'spring-boot', version: '2.1.6.RELEASE'
    implementation("org.springframework.boot:spring-boot-starter-web")

   //the rest of you dependencies add here


}

And after that I was able to generate the .jar directy by the terminal on the IDE running the following command:

gradlew clean build

The .jar generated you will find on your project folder in the directory called build/libs

Cheers!!!