My jar file P2.jar (which has a main method and manifest file) is located in C:\\Jar Folder
. I tried to run it from cmd like this:
C:SomeRandomFolder> java -jar C:\\Jar Folder\\P2.jar
I get the error:
unable to access jarfile C:\Jar
It works when I run it from the folder that the jar is in like this:
C:\Jar Folder> java -jar P2.jar
Why can't I use the 1st command? Why do I have to go to the directory of my jar file?
That's because of the space you have in the path name. On Windows, use quotes:
java -jar "C:\\Jar Folder\\P2.jar"
If you are in a terminal and the folder you are in is deleted out from underneath you and replaced with the same content, the jar file will be be visible with ls
, but will not be available since your current directory was deleted and replaced with one that looks just like it.
I got that error too:
el@apollo:/myproject/build/jar$ java -jar CalculateStats.jar
Unable to access jarfile CalculateStats.jar
To fix it. cd
up a directory and cd
back in, like this:
el@apollo:/myproject/build/jar$ cd ..
el@apollo:/myproject/build$ cd jar/
el@apollo:/myproject/build/jar$ java -jar CalculateStats.jar
Program completed successfully
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.