What causes the "Unable to access jarfile" error in Java?
Codemia Knowledge Hub ·
The "Unable to access jarfile" error means the JVM cannot find or read the JAR file you passed to java -jar. The most common cause is a wrong file path, but missing permissions, filename typos, unquoted spaces in paths, or a corrupt JAR can also trigger it. It is always a file access problem, not a Java code problem.
How java -jar resolves the file
When you run java -jar myapp.jar, the JVM does not search PATH or CLASSPATH. It treats the argument as a file path relative to the current working directory (or as an absolute path if you give one). If the file is not at that exact location, or the process cannot read it, you get:
The message comes from the JVM launcher before any Java code runs. It is not a Java exception; it is the operating system reporting that the file could not be opened.
Wrong file path or filename
This is the most frequent cause: the path in your command does not match where the file actually lives.
Verify the path and filename with ls or dir:
Then use the exact path:
On Linux, MyApp.jar and myapp.jar are different files. Windows and macOS (with its default case-insensitive APFS volume) ignore case, so a script that works there can fail on Linux.
Spaces in the path
Unquoted paths with spaces get split into separate arguments:
The same happens on Windows:
The JAR does not exist
The JAR was deleted, moved, or never built:
Typical reasons:
- The build step (
mvn package,gradle build) failed silently and never produced the JAR - A deployment script moved the file to a different directory
- A cron job or CI pipeline cleaned the file up
Rebuild or redeploy, then confirm the file exists before running:
Insufficient read permissions
The user running java cannot read the JAR:
On Windows, right-click the file, open Properties, then the Security tab, and confirm the executing user has Read permission.
Running from the wrong working directory
Relative paths resolve from the current working directory:
This is especially common in systemd services, cron jobs, and Docker containers, where the working directory may not be what you expect. Wrapper scripts that cd somewhere before running java -jar cause the same problem: relative paths resolve from the new directory, not from where you invoked the script.
A corrupt or invalid JAR
A truncated download, incomplete build, or wrong file type can also produce the error:
A symlink pointing to a missing target
If the JAR path is a symbolic link, its target might not exist:
Diagnostic checklist
| Check | Command | What It Verifies |
| File exists | ls -la /path/to/app.jar | Path and filename are correct |
| File is readable | test -r /path/to/app.jar && echo ok | Current user has read permission |
| File is a valid JAR | file /path/to/app.jar | Not a corrupt or wrong file type |
| Java is installed | java -version | JVM is available and on PATH |
| Working directory | pwd | Relative paths resolve correctly |
| Symlink target exists | readlink -f /path/to/app.jar | Link is not broken |
| No path spaces issue | Wrap path in quotes | Shell does not split the argument |
Platform-specific checks
Linux/macOS
Windows
Docker
Use the exec form of CMD (JSON array) to avoid shell interpretation issues, and make sure COPY puts the file at the path you reference in CMD.
Less obvious causes
Using ~ in the path. Tilde expansion is a shell feature. Where no shell expands it (such as a systemd ExecStart line without shell wrapping), the JVM looks for a literal directory named ~.
Confusing -cp with -jar. -jar tells Java to run a JAR file; -cp adds to the classpath. To run a class from a JAR on the classpath, use -cp myapp.jar com.example.Main instead of -jar myapp.jar.
Antivirus quarantine. Security software can quarantine JAR files because they are executable archives. If the file appears to exist but the JVM still cannot access it, check your antivirus logs.
Related reading
- What could be the cause of RejectedExecutionException
- What could cause java.lang.reflect.InvocationTargetException?
- What data type to use for money in Java?
- What difference does EnableConfigurationProperties make if a bean is already annotated with ConfigurationProperties?
- What causes unknown resolver null in Spark Kafka Connector?
- What causing this Invalid length for a Base-64 char array
- What do 3 dots next to a parameter type mean in Java?
- What do the different HotSpot JVM thread types do?
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.