0

I'm trying to create a simple jar program name Example.java which displaying "Hello World" to the user and the code are as follow:

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

and I have my manifest file as below:

Manifest-Version:1.0
Main-Class:C:\training\Java\JAR\s3\Example

when I run this command:

java -jar HelloWorld.jar

it returns

no main manifest attribute, in HelloWorld.jar

what is the problem here and why I cannot run the JAR file? I already look for some example but those were different from mine. Anyone care to help? Thanks!

1 Answers1

0

Main-Class:C:\training\Java\JAR\s3\Example

The Main-Class header should be a fully-qualified class name:

Main-Class: somePackage.Example

or just the class name if it is in the default package (bad practice):

Main-Class: Example

See:

If you have an application bundled in a JAR file, you need some way to indicate which class within the JAR file is your application's entry point. You provide this information with the Main-Class header in the manifest, which has the general form:

Main-Class: classname

The value classname is the name of the class that is your application's entry point

Community
  • 1
  • 1
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417