6

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:

  • Checking that the manifest file is in the correct folder and has the correct path in the artifact
  • Adding code to the build.gradle file for the jar->manifest portion
  • Trying the method of moving the manifest stuff into a resources folder
  • Checking that the jar exists
  • Moving the manifest stuff into a different folder (java,kotlin,out folders)
  • Making sure that the manifest file is in the correct format

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

lacanlale
  • 93
  • 1
  • 2
  • 9
  • Check out this please https://stackoverflow.com/questions/32567167/gradle-no-main-manifest-attribute. Try to update your `build.gradle` accordingly and then run the `build` task from Gradle. After that, you should get an executable jar file in the `build/libs` folder. – sedovav Jan 08 '18 at 10:06
  • I have seen this post and it has not worked either. I also do not see a libs folder in my build – lacanlale Jan 09 '18 at 06:42
  • You don't need a manifest file anywhere in your project. The only thing that you need is this `jar` task in your `build.gradle`. The task is run when the `build` task is run, so you need to run `./gradlew build` from the console to exclude any IntelliJ Idea specifics. In this case, you typically get a jar file in the `build/libs` folder of your Gradle project. The jar file should contain a generated manifest file. Everything is the same as with Java, Kotlins adds no specifics here. – sedovav Jan 09 '18 at 09:54
  • This was good help although I have read this before. However I have finally fixed the problem – lacanlale Jan 10 '18 at 06:18

3 Answers3

4

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!

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Robot
  • 70
  • 5
  • I had this problem using Gradle, but creating a project using Kotlin > JVM (this will use Maven) then putting a resource folder inside src folder there was no need to do anything else – Robot Aug 07 '20 at 22:07
3

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

lacanlale
  • 93
  • 1
  • 2
  • 9
0

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

  • This is half correct. I have already solved the problem and explicitly creating the manifest file is correct. However the extension should be .MF and should be placed in a META-INF folder. Thank you for your rseponse though – lacanlale Jan 17 '18 at 15:34