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

  • Thread starter Thread starter Wrichik Basu
  • Start date Start date
  • Tags Tags
    File
AI Thread Summary
The discussion revolves around the challenges of creating an executable JAR file in Apache NetBeans 11.0, which requires using Maven, Ant, or Gradle instead of a simple Java application setup. The user initially faced a "No main class" error when trying to run the JAR file, despite having a Main-Class attribute in the Manifest file. After attempting various solutions and compiling the classes from the command line, the user discovered that the command used to create the JAR file was crucial. The successful command was "jar cvfe myjar.jar BuildGUI *.class," which resolved the issue and allowed the application to run correctly. The user emphasized the importance of this solution for others facing similar problems.
Wrichik Basu
Science Advisor
Insights Author
Gold Member
Messages
2,180
Reaction score
2,717
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:
[CODE title="MANIFEST.MF"]Manifest-Version: 1.0
Main-Class: BuildGUI[/CODE]
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?
 
Technology news on Phys.org
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
 
  • Like
Likes sysprog
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
 
  • Like
Likes sysprog
Abraham Stones said:
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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
1
Views
2K
Replies
4
Views
3K
Replies
3
Views
15K
Replies
9
Views
3K
Replies
3
Views
3K
Replies
1
Views
3K
Replies
12
Views
4K
Back
Top