2

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?

3
  • Did you export it as a runnable jar file or just a jar file. Also does it run before you export it? Commented May 15, 2015 at 22:31
  • 2
    You need to run jars using java -jar Name.jar, not with -cp. Commented May 15, 2015 at 22:31
  • mtaschuk, that somehow worked. Thanks a bunch. 30 minutes down the drain... Commented May 15, 2015 at 22:41

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.