0

I m new to java and trying to learn about jar. I have created simple HelloWorld program. Created a jar file and trying to execute that jar.

HelloWorld.java

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}

Manifest.txt

Main-Class: HelloWorld

Following command to create jar

jar cfm HelloWorld.jar Manifest.txt HelloWorld.class

So far so good, when I m trying execute jar its showing below message

E:\Java_Example>java -jar HelloWorld.jar
no main manifest attribute, in HelloWorld.jar

However, when I did google about it, I found another command which works fine for me.

E:\Java_Example>java -cp HelloWorld.jar HelloWorld
Hello, World

I need to understand why "java -jar" command did not work for me? What changes I need to make to my program so that java -jar command will work?

Pravin Satav
  • 702
  • 5
  • 17
  • 36

0 Answers0