0

我创建了一个批处理文件来运行带有一些选项的可执行 jar。批处理中的代码是

java -jar target/%jar% %1

当我只运行 .bat 文件时,jar 会按预期执行,并且由于缺少参数,JAVA 程序会生成适当的警告。不幸的是,当我在批处理中放置一个文件时,我得到

Error: Unable to access jarfile target/someprogram.jar

当我在 .bat 本身中指定输入文件时,仅使用拖放操作不会发生错误。我还尝试在执行之前回显命令和参数,即使使用拖放操作,一切似乎都按预期进行。

任何如何解决此问题的想法将不胜感激。

4

1 回答 1

2

What I suspect is that the 'current path' is relative to the file being dragged rather than the bat.

There might be a way to get the pwd of the bat...

confirmed:

set PWD=%~dp0
echo %PWD%
pause

save this as whatever.bat, then drag and drop a file from another directory to it. You'll see that the operating directory is that of the file dragged, but %~dp0 will give you the directory where the bat resides.

于 2013-11-08T15:09:25.673 回答