Nik
Nik

Reputation: 375

Error: Could not Find or Load Main Class [Building and executing JAR File]

I am trying to create a JAR file for my code. I have tried it with both NetBeans and IntelliJ, on both Windows and Linux. In all cases, it gives me an error; Could not Find or Load Main Class.

Using NetBeans, I simply pressed Build for the project and the jar file was generated. I tried checking for the main manually (Right Click -> Properties -> Run) but it was set well already. It was set right packageName.Main. Also, I do have a public static void main(String[] args) method. The method compiles and works in the console, but when it comes to creating the Jar file, I get this error.

I have tried running the jar file using java -cp Name.jar Name, java Name.jar Name and a bunch of other commands, all to no avail.

Any ideas?

Thanks in advance.

EDIT: Although it works using cmd, I can't open the program when double clicking on the .jar file. Any ideas?

Upvotes: 2

Views: 609

Answers (1)

Nik
Nik

Reputation: 375

Done. Compile with java -jar Name.jar command. Thanks to mtaschuk

Upvotes: 1

Related Questions