0

I am trying to create my first jar file using:

jar cfvm myjar.jar manifest.txt Main.java

then run it using:

java -jar myjar.jar

which gives me the error msg:

Error: Could not find or load main class Main

Here are the contents of my manifest and source file

manifest.txt:

Main-Class: Main

Main.java:

    public class Main {
        public static void main(String[] args) {
            System.out.println("hello world");
            System.console().readLine();
        }
    }
Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305

1 Answers1

3
 jar cfvm myjar.jar manifest.txt Main.java

This should be something like

 jar cfvm myjar.jar manifest.txt Main.class

You can now also write something like

 jar cfve myjar.jar Main Main.class

(Also the standard name for a manifest file is manifest.mf as that is the name of the file in the archive. A little confusing otherwise.)

Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305
  • Thanks, I can run the program now with java -jar myjar.jar, however doubleclicking on the jar file gets nothing. –  Dec 24 '18 at 21:43
  • @J.W That'll need setting the file association in whatever operating system you are using. – Tom Hawtin - tackline Dec 24 '18 at 23:14
  • What do you mean by file extension? The jar when I tried to run it was already associated with Java platform se binary. –  Dec 25 '18 at 00:26
  • @J.W Oh I see. It doesn't open a window or anything like that. It just uses a console that it doesn't have. That'll be why you aren't seeing anything. – Tom Hawtin - tackline Dec 25 '18 at 00:30
  • Ah I understand now; https://stackoverflow.com/questions/28477529/what-happens-to-system-out-println-in-executable-jar –  Dec 25 '18 at 01:21