lacanlale
lacanlale

Reputation: 93

"no main manifest attribute" error in intellij when executing jar

I'm working on a kotlin project that I want to execute as a jar. This is all done in IntelliJ Idea and I went about making the jar using the artifacts.

The process I followed was (as illustrated by an Idea guide):

  1. Add artifact (as jar) from project structure
  2. Build jar
  3. Run jar

After this, I get a

'no main manifest attribute, in ____.jar'

What I have tried after reading several stack overflow questions:

All of the above has not worked.

Something that is confusing to me is that, even when I alter the manifest file to be in "incorrect" format, it still gives the same error. The path stated in the artifact's details is correct yet there is no difference even when I purposely input incorrect items in the manifest file. Not sure if that is the"real" problem but I'm also not sure how to fix that as well

Upvotes: 6

Views: 11634

Answers (3)

Robot
Robot

Reputation: 70

None of the solutions worked for me.

I solved it in this way:
When setting up the artifact, change:
Meta-inf: (...)\src\main\ (you must remove "java")

Also, there was a problem with resources, solved this way:
When setting up the artifact:
Output Layout > Add copy of > Directory content > resources.

That's all!

Upvotes: 4

Ujjawal prakash
Ujjawal prakash

Reputation: 1

while creating the exeutable jar file explicitly create a mainfest.txt file that should be in order of the directory structure and mainfest.txt file should contain only one line (Main-Class:name of the class containg main method)then run the jar tool

Upvotes: 0

lacanlale
lacanlale

Reputation: 93

For anyone that may have encountered this problem in intellij and did not find a solution in any other posts, what helped me was

  1. Navigating to Project Structure
  2. Going to the Artifacts tab
  3. Explicitly adding a new META-INF/ directory in my jar
  4. Adding the created MANIFEST.MF file to the META-INF/ in the jar FROM THE ARTIFACTS TAB
  5. Rearranging the order for the META-INF/ to be at the top
  6. Building and running

The end result looked like this

Upvotes: 3

Related Questions