Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Jar with Intellij 2016 - No main manifest attribute

I am getting no main manifest attribute while running the jar create by Intellij. I extracted the jar and observed that there was another manifest file, not the one I had specified while creating artifact.

When I open manifest in IDE, it displays everything right but after creating jar I get a whole new manifest file.

Manifest-Version: 1.0 Main-Class: YoutubeList 

I tried every solution from other answers and still not getting it right. Why creating a simple jar is hell of a task in Intellij, it was supposed to help developers!

Edited

And sometimes it does not include .class files in Jar which results in could not found or load class

like image 577
mallaudin Avatar asked Jun 12 '16 16:06

mallaudin


People also ask

How do I fix no main manifest attribute?

Sometimes this error may be encountered in your Spring Boot project. It is easy to resolve this error in the Spring Boot project. To fix this error in the SB project, put the maven-plugin dependency under the <plugins> tag in the pom. xml file.

Does a JAR file need a manifest?

The answer is the JAR file's manifest. The manifest is a special file that can contain information about the files packaged in a JAR file. By tailoring this "meta" information that the manifest contains, you enable the JAR file to serve a variety of purposes.

How do I specify JAR manifest?

You use the m command-line option to add custom information to the manifest during creation of a JAR file. This section describes the m option. The Jar tool automatically puts a default manifest with the pathname META-INF/MANIFEST. MF into any JAR file you create.


2 Answers

I was stucked with the same problem with maven build. When you are creating the artifact from project structure settings (ctrl+alt+shift+S), you have to change manifest directory:

<project folder>\src\main\java  

change java to resources

<project folder>\src\main\resources 

I have also used the option extract to the target JAR, and it's working well.

EDIT

You can find a detailed step-by-step, an other solutions here: https://stackoverflow.com/a/45303637/2640826

like image 177
Zsolt Tolvaly Avatar answered Sep 23 '22 11:09

Zsolt Tolvaly


I spent a few days to resolve it. My solution: I loaded a project that present in this answer. Then I compared and corrected settings of the loaded project and my own project. I compared/corrected:

  • Run/Debug Configurations
  • MANIFEST.MF
  • in Progect Structure settings: Project, Modules (mark what is sources, resources and etc), Artifacts.

In the end, I placed META-INF in resources directory.

Maybe i did excess actions, but it worked for me :)

P.S. also need to choose "Inherit project compile output path" in Progect Structure settings -> Modules -> Path

enter image description here

like image 25
Maksim Ryabovol Avatar answered Sep 23 '22 11:09

Maksim Ryabovol