JAR file won't run: "no main manifest attribute"
Hello everyone! I'm new to Java and trying to build my first project into an executable JAR file. The project is simple: there's one class `Main` with a `main` method that prints "Hello, World!". I compile the classes via command line, then create the JAR using the command:\n\n```\njar cf myapp.jar Main.class\n```\n\nAfter that I try to run:\n\n```\njava -jar myapp.jar\n```\n\nAnd I get the error:\n\n```\nno main manifest attribute, in myapp.jar\n```\n\nI checked that the `main` method is declared correctly — `public static void main(String[] args)`. What could be the problem? Do I need to specify something additional when creating the JAR? I read about the manifest, but I don't fully understand how to create it correctly. Please explain step by step what I'm doing wrong. Thanks in advance!\n\nExample of my code:\n\n```java
No answers yet.
Log in to leave an answer
Blogs
How to Pass a JavaScript Interview: Top Questions and Answers