Java:作为管理员运行时无法访问jarfile [英] Java: Unable to access jarfile when running as an admin

查看:105
本文介绍了Java:作为管理员运行时无法访问jarfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为test.jar的jar文件,我使用同一文件夹中的批处理脚本运行该文件。
这是批次代码:

I have a jar file named test.jar, which I am running with a batch script from the same folder. Here's the batch code:

java -jar test.jar
pause

jar本身没有任何问题,我可以正常运行它。
但是,如果我尝试以管理员身份运行批处理文件(通过右键单击并选择以管理员身份运行),我会收到以下错误:

The jar itself works with no problems, and I can run it just fine. However, if I try to run the batch file as an administrator (by right clicking it and choosing "Run as Administrator"), I get the following error:

Error: Unable to access jarfile test.jar

I我正在使用Windows 8.1,但这也发生在运行Windows 7的计算机上。
如果能够以管理员身份运行它,我该怎么做?

I'm using Windows 8.1, but this also happened on a machine running Windows 7. What can I do to be able to run this as an Administrator?

推荐答案

我有同样的问题,你和我通过改变来解决它

i had the same problem that you and i solved it by changing

java -jar test.jar

to

java -jar %~dp0test.jar

%~dp0保存目录您的bat文件(AFAIK)所以%~dp0将为Java提供解决问题的jar文件的完整路径。

%~dp0 holds the directory of your bat file (AFAIK) so %~dp0 will give Java the full path to the jar file solving the problem.

这篇关于Java:作为管理员运行时无法访问jarfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆