Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Unable to access jarfile when running as an admin

Tags:

java

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

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'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?

like image 386
Opalium Avatar asked Dec 23 '13 08:12

Opalium


People also ask

Why does it say unable to access JAR?

Encountering the “Unable to access jarfile /jar/minecraft_server. jar” error occurs when the server panel is unable to locate the designated JAR File that has been set. This can occur if the file has an incorrect name or if the original file was deleted for any reason.

Why is my executable JAR file not opening?

The first and simplest troubleshooting method for Jar file not opening is to reinstall Java Runtime Environment.


1 Answers

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

java -jar test.jar

to

java -jar %~dp0test.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.

like image 150
Juan Antonio Orozco Avatar answered Oct 06 '22 23:10

Juan Antonio Orozco