Java: unable to access jarfile when run as administrator

I have a jar file called test.jar that I run with a script package from the same folder. Here's the batch code:

java -jar test.jar pause 

The bank itself works without problems, and I can run it just fine. However, if I try to run the batch file as an administrator (by right-clicking on it and selecting "Run as administrator"), I get the following error:

 Error: Unable to access jarfile test.jar 

I am using Windows 8.1, but this also happened on a machine running Windows 7. What can I do to run this as an administrator?

+6
source share
2 answers

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

 java -jar test.jar 

to

 java -jar %~dp0test.jar 

% ~ dp0 contains the directory of your bat file (AFAIK), so% ~ dp0 will provide Java with the full path to the jar file, solving the problem.

+3
source

You can also declare a temporary path to java

path = C: \ Program Files \ Java \ jre1.8.0_40 \ bin Java script Path =

0
source

All Articles