Cannot run jar file: Could not find or load main class Hello

后端 未结 3 1070
太阳男子
太阳男子 2021-01-20 04:53

I create jar file in IDEA Build>Build Artifacts. But can\'t run it with java -jar jarname.jar - Error: Could not find or load main class Hello. MAN

3条回答
  •  余生分开走
    2021-01-20 05:16

    i believe your manifest file must say what the main class is if you want it to auto execute.

    Main-Class: Hello

    otherwise you need to specify it on the command line when attempting to execute the jar. As far as how to do that with IntelliJ, I can't help you there.

    java -cp hello.jar Hello

    Note that the reference to the class with the main method is the fully qualified location (package.classname) but since your class has the default package, its not necessary.

提交回复
热议问题