Problem in creating JAR file - "no main manifest attribute"

  • #1
1,322
1,129

Main Question or Discussion Point

I have three classes: Prog, CreateThread and BuildGUI. The last class has the main() method. I tested these classes using JDK 12 on NetBeans 11.0, and my program is working fine.

But I am being unable to create an executable JAR file. As you might be knowing, Apache NetBeans 11.0 no longer allows a simple Java application; instead, you must create an application with Maven, Ant or Gradle. I tried using the first, and followed several tricks from StackOverflow, but none of them worked. When I executed the JAR file from command line, it gave me an error, "No main class".

So I switched to creating the JAR file from command line itself. I put all of the three classes into one folder, and compiled them there. I removed the package statements for simplicity (earlier it was something like com.basuLabs.xyz). I followed the answers here to some extent, and wrote down a Manifest file:
MANIFEST.MF:
Manifest-Version: 1.0
Main-Class: BuildGUI
Then I create a JAR file using jar cfm myjar.jar MANIFEST.MF *.class, and run it using java -jar myjar.jar And I get irritated when I get the same error again and again:
no main manifest attribute, in myjar.jar

I can clearly see a Main-Class attribute in Manifest file. What is going wrong here? How can I share my application?
 

Answers and Replies

  • #2
1,322
1,129
Solution:

Just now I found the solution. I created the JAR file using a different set of commands:
jar cvfe myjar.jar BuildGUI *.class

This is working fine.

I am not requesting a thread deletion, because this seems to be a recurrent problem, and someone else might benefit from this solution.

Help taken from:
http://www.skylit.com/javamethods/faqs/createjar.html
 
  • #3
No main manifest error occurs because you did not define any starting point(i.e main method) for the application BuildGUI while creating the executable jar.

The MANIFEST.MF file that was generated by default did not contain Main-Class property in this case.

You just need to add the following line in MANIFEST.MF
Main-Class: BuildGUI

Hope this helps.

Source:
https://javahungry.blogspot.com/2019/05/solved-no-main-manifest-attribute-in-jar.html
 
  • #4
1,322
1,129
You just need to add the following line in MANIFEST.MF
Main-Class: BuildGUI
As I have written in the first post, I already added a main class attribute in the file. Even then it did not work. Changing the set of commands used to create the jar file, as indicated in post #2, did the trick.
 

Related Threads for: Problem in creating JAR file - "no main manifest attribute"

Replies
2
Views
2K
  • Last Post
Replies
6
Views
7K
Replies
3
Views
648
Replies
2
Views
805
Replies
13
Views
3K
  • Last Post
Replies
10
Views
11K
  • Last Post
Replies
2
Views
2K
Replies
4
Views
3K
Top