Avatar ·

JAR file won't start: "no main manifest attribute" — what to do?

Hello everyone! I'm a beginner in Java and trying to build a simple calculator into a JAR file to run it by double-click or via console. Compilation succeeds, but when I run java -jar myapp.jar, I get the error: "no main manifest attribute, in myapp.jar". Here is the structure of my project: ``` src/ com/ myapp/ Main.java Calculator.java ``` Main.java: ```java package com.myapp; public class Main { public static void main(String[] args) { System.out.println("Calculator started!"); Calculator calc = new Calculator(); System.out.println("2 + 3 = " + calc.add(2, 3)); } } ``` Calculator.java: ```java package com.myapp; public class Calculator { public int add(int a, int b) { return a + b; } } ``` I compile the classes: ``` javac -d out src/com/myapp/*.java ``` Then I create the JAR: ``` jar cf myapp.jar -C out . ``` In the out folder, the .class files are in the correct structure (com/myapp/)