0

Does anyone know that problem? I thought you could open executable .jar files with the java.exe.

When I run the .jar file from the cmd console with java -jar filename.jar it works completely fine and runs as intended. But when I tell it to open with the same java.exe that begins to run when I use the console command it gives:

Error: Could not find or load main class FilePath/filename.jar
Caused by: java.lang.ClassNotFoundException: FilePath/filename.jar

I first tried it with the java.exe in /bin/ from the built-in JRE from the JDK.

Then I downloaded the JRE from Oracle's website and used the java.exe in the /bin/ folder there.

Vladimir Vagaytsev
  • 2,871
  • 9
  • 33
  • 36
user10385242
  • 407
  • 1
  • 3
  • 10
  • `ClassNotFoundException: FilePath/filename.jar` thats the actuall message? – Antoniossss Sep 19 '18 at 11:19
  • **Wow** I am _impressed_ how much you can highlight for increased **readability**. – user10385242 Sep 19 '18 at 11:20
  • @Antoniossss No, it isn't. It uses the file path on to that file and the name of the jar. `C:\Users\TehHackerlord1337\Desktop\Cheese_jar\Cheese.jar` substitutes `FilePath/filename.jar` while TehHackerlord1337 is my username and Cheese.jar is the name of the jar-file. – user10385242 Sep 19 '18 at 11:23
  • I did delete the registry key entry for the default app to open .jar files according to: https://superuser.com/questions/49615/how-do-you-remove-a-default-program-association-for-file-types-in-windows-7 because it was suggesting to open the .jar file with a JRE version that I had already uninstalled. – user10385242 Sep 19 '18 at 11:27
  • I wonder why it is looking for class `*.jar` so I asked is that the real message as it supposed to be eg `some.package.ClassName` – Antoniossss Sep 19 '18 at 11:28
  • This is my manifest: `Manifest-Version: 1.0 Main-Class: com.cheese.JChess` is something wrong with it? It was automatically generated by IntelliJ Ideas Artifact Building feature. – user10385242 Sep 19 '18 at 11:34
  • There are new lines between them and also after the `Main-Class` row. Since from my testing around because of this problem I noticed that if you don't have a new line after the `Main-Class` row the **manifest** is recognized as corrupt. So it's not that as well. – user10385242 Sep 19 '18 at 11:38

1 Answers1

-1

Let's say you have a file C:\MyProject\app.jar.

When you run the following on the command line:

java -jar C:\MyProject\app.jar  # This works.

it works fine. The error you are seeing is the error you would get if you execute the following:

java C:\MyProject\app.jar       # This won't.

Note the missing -jar option. The solution is to write it like the first snippet: that -jar option is required. If this is happening when you doubleclick on it, your OS settings are messed up. If this is happening in a script, fix the script. If this is happening on the command line, write it with the -jar bit.

rzwitserloot
  • 85,357
  • 5
  • 51
  • 72
  • So do you know how to amend those messed up OS settings? – user10385242 Sep 19 '18 at 16:32
  • rzwitserloot I did delete the registry key entry for the default app to open .jar files according to: superuser.com/questions/49615/… because it was suggesting to open the .jar file with a JRE version that I had already uninstalled. – user10385242 Sep 19 '18 at 16:33