Last updated: July 2026
The basic command
java -jar application.jar
That’s it — if Java is installed and the JAR is executable (it declares a main class). Check Java first:
java -version
# no Java? On Ubuntu/Debian:
sudo apt install default-jre # runtime only
sudo apt install openjdk-21-jdk # current LTS, if you also compile
Pass arguments after the JAR name, and JVM options before -jar:
java -Xmx512m -jar application.jar --port=8080 input.csv
Error: “no main manifest attribute”
The JAR doesn’t declare an entry point in META-INF/MANIFEST.MF — it’s a library, not a runnable app. Two options:
# run a specific class from it
java -cp application.jar com.example.MainClass
Or, if you build it yourself, add the main class to the manifest (in Maven, the maven-jar-plugin/Spring Boot repackage does this).
To see what’s inside a JAR:
jar tf application.jar # list contents
unzip -p application.jar META-INF/MANIFEST.MF # read the manifest
Error: “UnsupportedClassVersionError … class file version 65.0”
The JAR was compiled with a newer Java than you’re running. Class file versions map to Java releases (61 = Java 17, 65 = Java 21). Install the matching (or newer) JDK, then pick it with:
sudo update-alternatives --config java
Running a JAR in the background / as a service
nohup java -jar app.jar & works for a quick test, but for anything real create a systemd unit — you get logs, restarts, and start-on-boot:
# /etc/systemd/system/myapp.service
[Unit]
Description=My Java App
After=network.target
[Service]
User=www-data
ExecStart=/usr/bin/java -jar /opt/myapp/application.jar
Restart=on-failure
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
journalctl -u myapp -f # follow the logs
Related: if your app runs on Tomcat instead of an embedded server, see configuring Tomcat to autostart on Ubuntu.
