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?
package ..;
though which I will try to add and see if it helps! – Bastipackage ..;
to the MainFrame class but it didn't work since gradle seemed to manage the packages. – Basti