What causes "Unable to access jarfile" error?

JavaJarExecutable Jar

Java Problem Overview


I want to execute my program without using an IDE. I've created a jar file and an exectuable jar file. When I double click the exe jar file, nothing happens, and when I try to use the command in cmd it gives me this:

Error: Unable to access jarfile <path>

I use the command: java -jar Calculator.jar

How I created the jar:

  1. Right click on project folder (Calculator)
  2. Select
  3. Click on Java Folder and select "Exectuable Jar File", then select next
  4. Launch Configuration: Main - Calculator
  5. Create Export Destination
  6. Hit "Finish" and profit! Well, not really.

Java Solutions


Solution 1 - Java

I had encountered this issue when I had run my Jar file as

java -jar TestJar

instead of

java -jar TestJar.jar

Missing the extension .jar also causes this issue.

Solution 2 - Java

Fixed

I just placed it in a different folder and it worked.

Solution 3 - Java

[Possibly Windows only]

Beware of spaces in the path, even when your jar is in the current working directory. For example, for me this was failing:

java -jar myjar.jar

I was able to fix this by givng the full, quoted path to the jar:

java -jar "%~dp0\myjar.jar" 

Credit goes to this answer for setting me on the right path....

Solution 4 - Java

I had this issue under CygWin in Windows. I have read elsewhere that Java does not understand the CygWin paths (/cygdrive/c/some/dir instead of C:\some\dir) - so I used a relative path instead: ../../some/dir/sbt-launch.jar.

Solution 5 - Java

I had the same issue when trying to launch the jar file. The path contained a space, so I had to place quotes around. Instead of:

java -jar C:\Path to File\myJar.jar

i had to write

java -jar "C:\Path to File\myJar.jar"

Solution 6 - Java

Just came across the same problem trying to make a bad USB...

I tried to run this command in admin cmd

java -jar c:\fw\ducky\duckencode.jar -I c:\fw\ducky\HelloWorld.txt  -o c:\fw\ducky\inject.bin

But got this error:

Error: unable to access jarfile c:\fw\ducky\duckencode.jar

Solution

1st step

Right click the jarfile in question. Click properties. Click the unblock tab in bottom right corner. The file was blocked, because it was downloaded and not created on my PC.

2nd step

In the cmd I changed the directory to where the jar file is located.

cd C:\fw\ducky\

Then I typed dir and saw the file was named duckencode.jar.jar

So in cmd I changed the original command to reference the file with .jar.jar

java -jar c:\fw\ducky\duckencode.jar.jar -I c:\fw\ducky\HelloWorld.txt  -o c:\fw\ducky\inject.bin

That command executed without error messages and the inject.bin I was trying to create was now located in the directory.

Hope this helps.

Solution 7 - Java

I had a similar problem and I even tried running my CMD with administrator rights, but it did not solve the problem.

The basic thing is to make sure to change the Directory in cmd to the current directory where your jar file is.

Do the following steps:

  1. Copy jar file to Desktop.

  2. Run CMD

  3. Type command cd desktop

  4. Then type java -jar filename.jar

This should work.


Edit: From JDK-11 onwards ( JEP 330: Launch Single-File Source-Code Programs )

Since Java 11, java command line tool has been able to run a single-file source-code directly. e.g.

java filename.java

Solution 8 - Java

If you are using OSX, downloaded files are tagged with a security flag that prevents unsigned applications from running.

to check this you can view extended attributes on the file

$ ls -l@
-rw-r--r--@ 1 dave  staff  17663235 13 Oct 11:08 server-0.28.2-java8.jar
com.apple.metadata:kMDItemWhereFroms         619
com.apple.quarantine          68

You can then clear the attributes with

xattr -c file.jar

Solution 9 - Java

None of the provided answers worked for me on macOS 11 Big Sur. The problem turned out to be that programs require special permission to access the Desktop, Documents, and Downloads folders, and Java breaks both the exception for directly opened files and the permission request popup.

Fixes:

  • Move the .jar into a folder that isn’t (and isn’t under) Documents, Desktop, or Downloads.
  • Manually grant the permission. Go to System Preferences → Security and Privacy → Privacy → Files and Folders → java, and check the appropriate folders.

Solution 10 - Java

This worked for me.

cd /path/to/the/jar/

java -jar ./Calculator.jar

Solution 11 - Java

It can also happen if you don't properly supply your list of parameters. Here's what I was doing:

java -jar test@gmail.com testing_subject file.txt test_send_emails.jar

Instead of the correct version:

java -jar test_send_emails.jar test@gmail.com testing_subject file.txt

Solution 12 - Java

For me it happens if you use native Polish chars in foldername that is in the PATH. So maybe using untypical chars was the reason of the problem.

Solution 13 - Java

sometime it happens when you try to (run or create) a .jar file under /libs folder by right click it in android studio. you can select the dropdown in top of android stuio and change it to app. This will work

enter image description here

Solution 14 - Java

My particular issue was caused because I was working with directories that involved symbolic links (shortcuts). Consequently, trying java -jar ../../myJar.jar didn't work because I wasn't where I thought I was.

Disregarding relative file paths fixed it right up.

Solution 15 - Java

In my case the suggested file name to be used was jarFile*.jar in the command line. The file in the folder was jarFile-1.2.3.jar . So I renamed the file to jarFile. Then I used jarFile.jar instead of jarFile*.jar and then the problem got resolved

Solution 16 - Java

It can happen on a windows machine when you have spaces in the names of the folder. The solution would be to enter the path between " ". For example:

java -jar c:\my folder\x.jar    --> 
java -jar "c:\my folder\x.jar"

Solution 17 - Java

To avoid any permission issues, try to run it as administrator. This worked for me on Win10.

Solution 18 - Java

I know this thread is years ago and issue was fixed too. But I hope this would helps someone else in future since I've encountered some similar issues while I tried to install Oracle WebLogic 12c and Oracle OFR in which its installer is in .jar format. For mine case, it was either didn't wrap the JDK directory in quotes or simply typo.

Run Command Prompt as administrator and execute the command in this format. Double check the sentence if there is typo.

> "C:\Program Files\Java\jdk1.xxxxx\bin\java" -jar C:\Users\xxx\Downloads\xxx.jar

If it shows something like JRE 1.xxx is not a valid JDK Java Home, make sure the System variables for JAVA_HOME in Environment Variables is pointing to the correct JDK directory. JDK 1.8 or above is recommended (2018).

A useful thread here, you may refer it: Why its showing your JDK c:program files\java\jre7 is not a valid JDK while instaling weblogic server?

Solution 19 - Java

I had a similar problem where TextMate or something replaced the double quotes with the unicode double quotes.

Changing my SELENIUM_SERVER_JAR from the unicode double quotes to regular double quotes and that solved my problem.

Solution 20 - Java

this is because you are looking for the file in the wrong path

  1. look for the path of the folder where you placed the file
  2. change the directory cd in cmd use the right path

Solution 21 - Java

I use NetBeans and had the same issue. After I ran build and clean project my program was executable. The Java documentation says that the build/clean command is for rebuilding the project from scratch basically and removing any past compiles. I hope this helps. Also, I'd read the documentation. Oracle has NetBeans and Java learning trails. Very helpful. Good luck!

Solution 22 - Java

Maybe you have specified the wrong version of your jar.

Solution 23 - Java

I finally pasted my jar file into the same folder as my JDK so I didn't have to include the paths. I also had to open the command prompt as an admin.

  1. Right click Command Prompt and "Run as administrator"
  2. Navigate to the directory where you saved your jdk to
  3. In the command prompt type: java.exe -jar <jar file name>.jar

Solution 24 - Java

Keep the file in same directory where you are extracting it. That worked for me.

Solution 25 - Java

For me it happen because i run it with default java version (7) and not with compiled java version (8) used to create this jar.

So i used:

%Java8_64%\bin\java -jar myjar.jar

Instead of java 7 version:

java -jar myjar.jar

Solution 26 - Java

This is permission issue, see if the directory is under your User. That's why is working in another folder!

Solution 27 - Java

Have you tried to run it under administrator privoleges? meaning, running the command in "Run As" and then select administrator with proper admin credentials

worked for me

Solution 28 - Java

I was trying this:

After giving the file read, write, execute priviledges:

chmod 777 java-repl.jar

alias jr="java -jar $HOME/Dev/java-repl/java-repl.jar"

Unable to access bla bla..., this was on Mac OS though

So I tried this:

alias jr="cd $HOME/Dev/java-repl/ && java -jar java-repl.jar"

Solution 29 - Java

This did not work "Unable to access jarfile"

"C:\Program Files\java\jdk-13+33-jre\bin\javaw.exe" -jar "C:\Program Files\Maxim Integrated Products\1-Wire Drivers x64\ OneWireViewer.jar"

This does work

"C:\Program Files\java\jdk-13+33-jre\bin\javaw.exe" -jar "C:\Program Files\Maxim Integrated Products\1-Wire Drivers x64\OneWireViewer.jar"

The difference is the single space in front of OneWireViewer.jar not withstanding that it is surrounded with quotes and even has other spaces.

Solution 30 - Java

If you are on WSL, and following a guide which say, says this:

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

You actually need to specify the full path, even though you've provided it in the java.library.path part.

java -Djava.library.path=/mnt/c/dynamodb_local/DynamoDBLocal_lib -jar /mnt/c/dynamodb_local/DynamoDBLocal.jar -sharedDb

Solution 31 - Java

Rename the jar file and try

Explanation : yes, I know there are many answers still I want to add one point here which I faced.

I built the jar and I moved it into the server where I deploy (This is the normal process) here the file name which I moved already existed in the server, here the file will override obviously right. In this case, I faced this issue. maybe at the time of overriding there can be a permission copy issue.

Hope this will help someone.

Solution 32 - Java

For me the problem got resolved after accessing the folder in which the jar was placed earlier I was giving command on D: drive, but when I navigated to the folder in which that jar was placed this problem got resolved

Solution 33 - Java

first I created a variable %JAVA_HOME% :

When you downloaded the file, make sure to check UNBLOCK TAB in file properties as shown above in "maartencls" post .

c:\users\my user\downloads\location of the file\all> java -jar yourfilename.jar

hope this will resolve the issue :)

Solution 34 - Java

First run: java -version

and then run: java -jar Calculator.jar

This worked for me.

Solution 35 - Java

You can specify full path to your java.exe file, fo example: "c:\Program Files\Java\jdk-9.0.4\bin\java.exe" -jar path_to_your_jar_file.jar it's help for me. Or check what java.exe file runs for default in you system (espacially if you have many version of JDK/JRE).

Solution 36 - Java

In my issue to access directory from Command line (in windows) this error

> "unnable to access ..."

because wrong file extension

> file.jar.jar

! , so change it to correct one

> file.jar

:) good luck

Solution 37 - Java

Right click the parent folder of the file > properties > check off Read Only

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoseph SmithView Question on Stackoverflow
Solution 1 - JavaVinay KadalagiView Answer on Stackoverflow
Solution 2 - JavaJoseph SmithView Answer on Stackoverflow
Solution 3 - JavaRobert BrownView Answer on Stackoverflow
Solution 4 - JavaradumanolescuView Answer on Stackoverflow
Solution 5 - JavabenezView Answer on Stackoverflow
Solution 6 - JavaLeon thomasView Answer on Stackoverflow
Solution 7 - JavaVishwa RatnaView Answer on Stackoverflow
Solution 8 - Javanick foxView Answer on Stackoverflow
Solution 9 - JavatwhbView Answer on Stackoverflow
Solution 10 - JavaBastian Cáceres PinoView Answer on Stackoverflow
Solution 11 - JavaBuffaloView Answer on Stackoverflow
Solution 12 - JavaHuxwellView Answer on Stackoverflow
Solution 13 - Javaanand krishView Answer on Stackoverflow
Solution 14 - JavaMattSayarView Answer on Stackoverflow
Solution 15 - JavasukuView Answer on Stackoverflow
Solution 16 - JavaassafView Answer on Stackoverflow
Solution 17 - JavaGicoView Answer on Stackoverflow
Solution 18 - Javanot_PrinceView Answer on Stackoverflow
Solution 19 - JavaTankorSmashView Answer on Stackoverflow
Solution 20 - JavafelipeView Answer on Stackoverflow
Solution 21 - Javauser8315373View Answer on Stackoverflow
Solution 22 - Javacosbor11View Answer on Stackoverflow
Solution 23 - JavaMichaela BurnsView Answer on Stackoverflow
Solution 24 - JavaAishwary joshiView Answer on Stackoverflow
Solution 25 - JavaAdir DView Answer on Stackoverflow
Solution 26 - JavaDimitriosView Answer on Stackoverflow
Solution 27 - JavaNick_Stubborn_Mex.View Answer on Stackoverflow
Solution 28 - JavaKingleeView Answer on Stackoverflow
Solution 29 - JavaangarView Answer on Stackoverflow
Solution 30 - JavaAncientSwordRageView Answer on Stackoverflow
Solution 31 - JavaSainath PabbaView Answer on Stackoverflow
Solution 32 - Javanikhil udgirkarView Answer on Stackoverflow
Solution 33 - Javamouf lowView Answer on Stackoverflow
Solution 34 - JavaSruthyView Answer on Stackoverflow
Solution 35 - JavaIhar PakView Answer on Stackoverflow
Solution 36 - JavaSayid BroView Answer on Stackoverflow
Solution 37 - JavaKidView Answer on Stackoverflow