Error unable to access jarfile C: \ Jar

My jar P2.jar file (which has the main method and manifest file) is located in C:\Jar Folder . I tried to run it from cmd as follows:

C:SomeRandomFolder> java -jar C:\Jar Folder\P2.jar

I get an error message:

 unable to access jarfile C:\Jar 

It works when I run it from the folder the jar is in:

 C:\Jar Folder> java -jar P2.jar 

Why can't I use the 1st command? Why do I need to go to the directory of my jar file?

+8
java command-line
source share
2 answers

This is because of the space that you have in the path name. On Windows, use quotation marks:

java -jar "C:\Jar Folder\P2.jar"

+22
source share

If you are in the terminal and the folder you are in is deleted from you and replaced with the same content, the jar file will be displayed using ls , but will not be accessible, since your current directory has been deleted and replaced with that that looks the same.

I also got this error:

 el@apollo:/myproject/build/jar$ java -jar CalculateStats.jar Unable to access jarfile CalculateStats.jar 

To fix it. cd return the directory and cd back, for example:

 el@apollo:/myproject/build/jar$ cd .. el@apollo:/myproject/build$ cd jar/ el@apollo:/myproject/build/jar$ java -jar CalculateStats.jar Program completed successfully 
0
source share

All Articles