1What Java is telling you
The name after "jarfile" is the file Java looked for, exactly as it read your command, and it's the first clue. On 29 Sep we ran each of these with Java 21 on Linux, next to Minecraft 1.21.1's server jar:
| What we ran | What Java said |
|---|---|
java -jar server.jar, with no file of that name in the folder | Error: Unable to access jarfile server.jar |
The same, where the file is really server.jar.jar | Error: Unable to access jarfile server.jar |
java -jar Server.jar, where the file is server.jar | Error: Unable to access jarfile Server.jar |
java -jar My Server/server.jar, without quotes | Error: Unable to access jarfile My |
| A jar the user isn't allowed to read | Error: Unable to access jarfile locked.jar |
A download cut short, or a folder named .jar | Error: Invalid or corrupt jarfile broken.jar |
| A library's jar instead of a server's | no main manifest attribute, in netty-common-4.1.97.Final.jar |
2The fix for each
- Use the name the file really has. List the folder, with
lson Linux ordiron Windows, and copy the name from there. Windows hides known file extensions unless you turn them on in File Explorer's View menu, so a file renamed toserver.jarthere is oftenserver.jar.jar. On Linux,Server.jarandserver.jarare two different names. - Run the command in the jar's folder. A start script launched from somewhere else looks for the jar there. Our script failed when run from another folder, and worked once its first line was
cd "$(dirname "$0")". In a Windows.batfile,cd /d "%~dp0"does the same. - Put quotes around a path with spaces:
java -jar "My Server/server.jar"started the server where the same path without quotes stopped atMy. - After an update, match the new name. Paper names each download after its version and build, like
paper-1.21.1-133.jar, so a script that names the old build finds nothing. Rename the file, or change the script. - Let your user read the file. On Linux,
ls -l server.jarshows who may, andchmod a+r server.jarlets everyone. - Invalid or corrupt jarfile: download it again. Our copy of the 51.6 MB server jar cut off after its first 100 kB gave that error. Mojang lists each server jar's SHA-1 and Paper each build's SHA-256, so
sha1sumorsha256sumtells whether yours is whole. - No main manifest attribute: that's not the server. Plugins, mods and libraries are jars too. Run the server's own jar, or its installer for Forge and NeoForge.
3A full path works, but mind where the files go
java -jar /home/you/server/server.jar nogui starts the server from any folder. It then writes eula.txt, server.properties and logs, and later the world, into the folder the command ran in, not next to the jar: ours made them all in the other folder, and asked for the EULA there. So cd into the server's folder first, as the scripts above do.
4On a Playkeeper server
There's no java -jar to type. Playkeeper downloads each server's software itself, checks it before the first start, and starts it in its own container, with the Java that Minecraft version needs.
Questions
Why does it say Unable to access jarfile when the file is there?
Its real name differs, like server.jar.jar with Windows hiding the extension or a capital letter on Linux, the command runs in another folder, or your user can't read the file.
What's the difference from Invalid or corrupt jarfile?
Unable to access means Java couldn't open a file by that name at all. Invalid or corrupt means it opened one, but it isn't a whole jar: a download cut short, or a folder with a .jar name.
Where do a server's files go when I start it with a full path?
Into the folder the command runs in, not next to the jar. Change into the server's folder first.