1

I have the code located in this path- W:\My Project\Missing.jar... When i have spaces in my existing folder "My Project"(Note: Folder name with space), on running the command java -jar %~dp0\Missing.jar, i am getting error as - Error: Unable to access jarfile W:\My, its is not able to locate the jar if i have spaces in my folder name.

But its is working when the folder name is MyProject(Note: Without any space), that means its working if i have the jar file located at W:\MyProject\Missing.jar

How i can make it to work even if the folder has spaces

Shiv
  • 101
  • 3
  • 15
  • [This link](https://stackoverflow.com/questions/5034076/what-does-dp0-mean-and-how-does-it-work) might help to understand if that you are trying to achieve is really possible. – Romeo Sierra Dec 23 '18 at 01:23
  • 1
    `%~dp0\Missing.jar` Might be needing it's own quotes within the command. – John Kens Dec 23 '18 at 01:31
  • @ Romeo- Not able to find anything helpful there..my code code works if i am using under cd even with spaces but not with java -jar – Shiv Dec 23 '18 at 01:32
  • @JohnKens- Thanks a lot, it worked when used under quotes- have to use like this----> java -jar "%~dp0\Missing.jar" (%~dp0\Missing.jar should be quoted) instead of --> java -jar %~dp0\Missing.jar – Shiv Dec 23 '18 at 01:37

1 Answers1

4

It worked when used under quotes- have to use like this----> java -jar "%~dp0\Missing.jar" (%~dp0\Missing.jar should be quoted) instead of --> java -jar %~dp0\Missing.jar

John Kens
  • 1,615
  • 2
  • 10
  • 28
Shiv
  • 101
  • 3
  • 15
  • 6
    This is pretty much a duplicate question and answer. This is probably one of the top 3 mistakes newbies make with batch files. – Squashman Dec 23 '18 at 02:50