By Miłosz Tomkiel


2020-05-22 23:05:31 8 Comments

So I have file Test.java with simple main class code.

public class Test {
  public static void main(String[] args) {
    System.out.println("123");
  }
}

and MANIFEST.MF file with:

Main-Class: Test

Then in CMD I type:

javac -verbose Test.java

then

jar cmf MANIFEST.MF Test.jar Test.class Test.java

then

java -jar Test.jar

with output:

Error: Could not find or load main class Test

1 comments

@Elliott Frisch 2020-05-23 00:19:17

I could reproduce your original error, which was caused by not having a newline after the Main-Class declaration in the manifest. The following is a complete shell log of the commands and files used:

bash-5.0$ ls
MANIFEST.MF Test.java
bash-5.0$ cat MANIFEST.MF
Main-Class: Test

bash-5.0$ cat Test.java
public class Test {
  public static void main(String[] args) {
    System.out.println("123");
  }
}
bash-5.0$ javac Test.java
bash-5.0$ jar cmf MANIFEST.MF Test.jar Test.class Test.java
bash-5.0$ java -jar Test.jar
123
bash-5.0$

@Miłosz Tomkiel 2020-05-23 18:59:58

And I'm getting same error doing the same thing as you, weird.

Related Questions

Sponsored Content

66 Answered Questions

[SOLVED] How do I generate random integers within a specific range in Java?

  • 2008-12-12 18:20:57
  • user42155
  • 4050722 View
  • 3497 Score
  • 66 Answer
  • Tags:   java random integer

49 Answered Questions

[SOLVED] Does a finally block always get executed in Java?

44 Answered Questions

[SOLVED] How do I convert a String to an int in Java?

87 Answered Questions

[SOLVED] Is Java "pass-by-reference" or "pass-by-value"?

32 Answered Questions

[SOLVED] When to use LinkedList over ArrayList in Java?

57 Answered Questions

[SOLVED] How to create a memory leak in Java?

42 Answered Questions

[SOLVED] How do I efficiently iterate over each entry in a Java Map?

37 Answered Questions

[SOLVED] Can't execute jar- file: "no main manifest attribute"

59 Answered Questions

[SOLVED] How do I read / convert an InputStream into a String in Java?

30 Answered Questions

Sponsored Content