What causes "Unable to access jarfile" error?

I want to execute my program without using an IDE. I've created a jar file and an exectuable jar file. When I double click the exe jar file, nothing happens, and when I try to use the command in cmd it gives me this:

Error: Unable to access jarfile <path>

I use the command: java -jar Calculator.jar

How I created the jar:

  1. Right click on project folder (Calculator)
  2. Select
  3. Click on Java Folder and select "Exectuable Jar File", then select next
  4. Launch Configuration: Main - Calculator
  5. Create Export Destination
  6. Hit "Finish" and profit! Well, not really.

Solution 1:

I had encountered this issue when I had run my Jar file as

java -jar TestJar

instead of

java -jar TestJar.jar

Missing the extension .jar also causes this issue.

Solution 2:

Fixed

I just placed it in a different folder and it worked.

Solution 3:

[Possibly Windows only]

Beware of spaces in the path, even when your jar is in the current working directory. For example, for me this was failing:

java -jar myjar.jar

I was able to fix this by givng the full, quoted path to the jar:

java -jar "%~dp0\myjar.jar" 

Credit goes to this answer for setting me on the right path....

Solution 4:

I had this issue under CygWin in Windows. I have read elsewhere that Java does not understand the CygWin paths (/cygdrive/c/some/dir instead of C:\some\dir) - so I used a relative path instead: ../../some/dir/sbt-launch.jar.

Solution 5:

I had the same issue when trying to launch the jar file. The path contained a space, so I had to place quotes around. Instead of:

java -jar C:\Path to File\myJar.jar

i had to write

java -jar "C:\Path to File\myJar.jar"